Python User Input


For user input, Python enables.

This means that we can request input from the user.

In Python 3.6 the approach is slightly different from Python 2.7.

The input() function is used for Python 3.6.

The raw_input() function is used for Python 2.7.

The sample below asks for the username, and it is printed on screen when you entered the username:


Python 3.6 input() Method

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

Output :-

Enter username: abc
Username is : abc

Python 2.7 raw_input() Method

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

Output :-

Enter username: abc
Username is : abc

Python stops running when the input() feature is involved and proceeds when the user has entered some information.