User Input

suggest change

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

user_input = raw_input()

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

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:

try:
    input = raw_input
except NameError:
    pass

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents