Python Language Incompatibilities moving from Python 2 to Python 3 User Input

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

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:

try:
    input = raw_input
except NameError:
    pass


Got any Python Language Question?