Python Command Line Input

Course Recommendation:

Command Line Input

Python allows command line input.

This means we can ask the user to enter.

The method in Python 3.6 is slightly different from Python 2.7. Used in Python 3.6 Method.

Used in Python 2.7 raw_input() Method.

The following example will ask for the user's name, and when you enter your name, it will be printed on the screen:

Python 3.6

print("Enter your name:")
x = input()
print("Hello ", x)

Python 2.7

print("Enter your name:")
x = raw_input()
print("Hello ", x)

Save this file as demo_string_input.pyand load it via the command line:

C:\Users\Your Name>python demo_string_input.py

Our program will prompt the user to enter a string:

Enter your name:

Now the user enters a name:

Bill

Then, the program will print a message:

Hello, Bill