difference between raw_input() and input()

B

baalu aanand

Hi,

I have used both raw_input() and input() for a same input value.
But these gives different output.

I have listed below what actually I have done
'023'

I have given the same value for the input() but it gives 19 as
result 19

Is there anything hide within this. Please illustrate the difference
between raw_input() and input()

Thanks in advance
Baalu
 
C

Chris Rebert

Hi,

    I have used both raw_input() and input() for a same input value.
But these gives different output.

    I have listed below what actually I have done

           >>> a = raw_input("===>")
                  ===> 023
           >>> a
                   '023'

    I have given the same value for the input() but it gives 19 as
result
           >>> a = input("===>")
                  ===>  023
           >>> a
                   19

 Is there anything hide within this. Please illustrate the difference
between raw_input() and input()

input() === eval(raw_input())
eval("023") --> int("23", 8) --> 19 [an integer, not a string]

raw_input() /always/ returns a string.

Never use input() in Python 2.x. In Python 3, raw_input() was renamed
to input() because it's a better name and the old input() was hardly
ever used (correctly).

Cheers,
Chris
 
S

Steven D'Aprano

Hi,

I have used both raw_input() and input() for a same input value.
But these gives different output.

I have listed below what actually I have done

'023'

I have given the same value for the input() but it gives 19 as
result
19

Is there anything hide within this. Please illustrate the difference
between raw_input() and input()


Did you look them up in the documentation?

Did you try the interactive help?

help(input)
help(raw_input)



Perhaps you could try some further experiments:

hello world
'hello world'hello world
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1
hello world
^
SyntaxError: unexpected EOF while parsing


Does that give you a hint as to what is happening?

How about this?
File "<stdin>", line 1
08
^
SyntaxError: invalid token010
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top