0

Can we input something in a data type other than string in Python?? I cant seem to carry out arithmetic operation on input var.

15th Apr 2018, 5:08 PM
Prachi Pandit
4 Réponses
+ 1
thank you for explaining it so well 😃
15th Apr 2018, 5:33 PM
Prachi Pandit
0
Input something other than string? x = int(input()) # integer input y = int(input()) print("Sum = {}".format(x + y)) PS: Prachi Pandit, if you want to input data that is not a string then, Yes, you will have to type-cast it! Note that (x + y) is an integer. That is why, I used .format() to convert it to string 😉
15th Apr 2018, 5:16 PM
777
777 - avatar
0
so do we need to typecast it every time? in order to carry out operations?
15th Apr 2018, 5:21 PM
Prachi Pandit
0
and is it by default input in a string type?? and I can't understand why you included 'format' in your output
15th Apr 2018, 5:21 PM
Prachi Pandit