Python Command Line Input

Command Line Input

Python ay nagbibigay ng pagpasok ng command line.

This means we can ask the user to input.

Ang mga paraan sa Python 3.6 ay halos magkakaiba sa Python 2.7.

Python 3.6 sa Paggamit input() Method.

Python 2.7 sa Paggamit raw_input() Method.

The following example will ask for the user's name, and when you enter a 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 their name:

Bill

Then, the program will print a message:

Hello, Bill