How to use Python's command line input method
May 10, 2023 pm 12:34 PMCommand line input
Python allows command line input.
This means we can ask for input from the user.
The approach in Python 3.6 is slightly different than in Python 2.7.
Python 3.6 uses the input() method.
Python 2.7 uses the raw_input() method.
The following example will ask the user for their name, and when the name is entered, the name will be printed to 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.py
and 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 the name:
Bill
Then, the program will print a message:
Hello, Bill
The above is the detailed content of How to use Python's command line input method. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What are the advantages and disadvantages of templating?

Google AI announces Gemini 1.5 Pro and Gemma 2 for developers

For only $250, Hugging Face's technical director teaches you how to fine-tune Llama 3 step by step

A complete guide to golang function debugging and analysis

Share several .NET open source AI and LLM related project frameworks
