Difference between input() and raw_input() in Python?


#1

I’ve recently started learning Python. Previously I learned to use input().

However, in my current lesson, 3/11 PygLatin, it is using raw_input().

Can someone tell me the difference between the two?


#2

to understand the difference, you need to understand that there are two major version of python: python2 and python3

when python3 was released, the decision was made to make some fundamental and make python3 not backward compatible with python2. This means, there still exist and a lot of python2 code in the world, given its expensive to rewrite to python3.

python2 has both a raw_input and input function, however the input function evaluates the input as code (in python2 that is), and raw_input will take the input and store it as a string

in python3, raw_input no longer exist. Its now input, which is the equivalent of python2 raw_input

so in python3, input will get input and store it as string

that is the difference


#3

See:

It is almost always wise to avoid using input in Python 2. It can offer hackers an opportunity to enter mischievous code at the prompt. Use raw_input instead, and convert the entered str to another type when necessary.


#4

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