Python Language User Input


In Python 2, user input is accepted using the raw_input function,

Python 2.x2.3
user_input = raw_input()

While in Python 3 user input is accepted using the input function.

Python 3.x3.0
user_input = input()

In Python 2, the input function will accept input and interpret it. While this can be useful, it has several security considerations and was removed in Python 3. To access the same functionality, eval(input()) can be used.

To keep a script portable across the two versions, you can put the code below near the top of your Python script:

    input = raw_input
except NameError: