+ 1
I don't understand how to use 'input' statement . Please any one tell me.
input statement in python.
3 Answers
+ 5
some more useful information about using input() in python
You also need to know some more details about using input() function in Python. Whatever you enter, the function will return it as a string.
If you enter >Tom< it will be returned as 'Tom'
If you enter >237< it will be returned as '237'
So both are strings. If you need your input for a calculation you have to convert it to int or float.
This can be done in several ways:
num = input('enter a number')
num = int(num)
res = num * 2
...
Or:
num = input('enter a number')
res = int(num) * 2
...
Or:
num = int(input('enter a number'))
res = num * 2
...
+ 4
#python 3
name=input("Write name:")
print(name)
#python 2
name= raw_input("Write your name:")
print name
+ 2
Thanks