32. User Input

By | October 6, 2021

User Input

Python allows for user input.

That means we are able to ask the user for input.

The method is a bit different in Python 3.6 than Python 2.7.

Python 3.6 uses the input() method.

Python 2.7 uses the raw_input() method.

The following example asks for the username, and when you entered the username, it gets printed on the screen:

Python 3.6

username = input(“Enter username:”)
print(“Username is: ” + username)

Output:
C:\Users\My Name>python demo_user_input3.py
Enter username:
Username is: krupa

Python 2.7

username = raw_input(“Enter username:”)
print(“Username is: ” + username)

Output:
C:\Users\My Name>python demo_user_input2.py
Enter username:
Username is: Nidhi

Leave a Reply

Your email address will not be published. Required fields are marked *