Can anyone tell me the difference between input
and raw_input
in Python and what is the proper way to use both?
Can anyone tell me the difference between input
and raw_input
in Python and what is the proper way to use both?
The difference is that raw_input()
does not exist in Python 3.x , while input()
exists. In fact the old raw_input()
has been renamed to input()
and the old input()
no longer exists (although it can be simulated using eval(input()).
As far as I'm researching, in Python 2.x , the command input()
"evaluates" the context in which the call was made. Here's an example:
>>> x = input()
"hello"
>>> y = input()
x + " world"
>>> y
'hello world'
The raw_input () returns the value typed as string, and the input () returns the value as integer Note: input () only accepts numbers