Raw_input() vs input()?


In step 8/19
He is telling me to make:

guess_row = int(raw_input("Guess Row: "))
guess_col = int(raw_input("Guess Col: "))

But, I used:

guess_row = input("Guess Row: ")
guess_col = input("Guess Col: ")

And as:

print type(guess_row)

It will give me ‘int’ …

So, just to be sure, is what I’m saying is correct ?
I’m totally new to python, and using Python 3.5 on my pc, not 2.7 as I think it is in the site …


Hi @mrkamoool,

With Python 2.7, you should do this …

guess_row = int(raw_input("Guess Row: "))
guess_col = int(raw_input("Guess Col: "))

… but with Python 3.5, do this …

guess_row = int(input("Guess Row: "))
guess_col = int(input("Guess Col: "))

It is best not to use input with Python 2.7, but in Python 3.x versions, input replaces raw_input.



Comparison of raw_input and input in Pyhon 2.7.x:

print type(input('num: '))

print type(raw_input('num: '))


num: 3
<type 'int'>
num: 3
<type 'unicode'>

The reason the first type is int is because the interpreter evaluated the input and saw that it was a number so cast it to that type. The operative word here is eval which many would say is evil since it permits code to be injected as user input. Very bad for business if a savvy hacker finds this vulnerability. I believe this is the cautionary meaning behind,


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.