Python User Input

Discover how to handle user input in Python with methods for both Python 3.6 and Python 2.7. Learn how to use the input() method to interact with users and retrieve their responses in your Python applications.



Python User Input

Python allows for user input, enabling interaction with the user. The method for obtaining user input differs between Python 3.6 and Python 2.7.

User Input in Python 3.6

In Python 3.6 and later, the input() method is used to get user input. The following example asks for the username and prints it:

Example

username = input("Enter username: ")
print("Username is: " + username)

User Input in Python 2.7

In Python 2.7, the raw_input() method is used for user input. Here is an example that performs the same task:

Example

username = raw_input("Enter username: ")
print("Username is: " + username)

Note: Python stops executing when it comes to the input() function, and continues when the user has given some input.