How does python get input examples from the keyboard

Use input() function in python to get user input

The function input() lets the program pause and waits for the user to input some text. After getting the user's input, Python stores it in a variable for later use.

name =input("Tell me your name,and I will repeat it back to you:")print(name)

The function input() receives a parameter, which is a prompt or description that the user wants to show, so that the user knows what to do. After the user enters and press the enter key, the next sentence will be executed,

The input by the user has been stored in the variable name. If you print name, the name entered by the user is printed.

It should be noted that input() stores a string. Even if the input is a number, Python will also store it as a string of numbers. Mathematical operations cannot be performed. If you want to perform mathematical operations,

You need to use the function int() to convert a string to a number type:

age =input("tell me your age? ")ifint(age)=18:print("age  = 18")else:print("age < 18")

Knowledge point expansion:

Python reads keyboard input

raw_input function

The raw_input([prompt]) function reads a line from standard input and returns a string (with the trailing newline removed)

#! /usr/bin/python
str =raw_input("Enter your input: ");
print "Received input is : ", str

input function

The input([prompt]) function and raw_input([prompt]) function are basically interchangeable, but input will assume that your input is a valid Python expression and return the result of the operation.

#! /usr/bin/python
str =input("Enter your input: ");
print "Received input is : ", str

So far, this article on how python obtains input from the keyboard is introduced. For more related python how to obtain input from the keyboard, please search the previous articles of ZaLou.Cn or continue to browse the related articles below. Hope you will support more in the future ZaLou.Cn!

Recommended Posts

How does python get input examples from the keyboard
How does python change the environment
How does python improve the calculation speed
How does Python handle the json module
How does python call the key of a dictionary
How does python handle the program cannot be opened
How does python judge the module installation is complete
How does Python output integers
How does python output backslashes
How does python update packages
How does python perform matrix operations
How does Python list update value
How Python implements the mail function
How to save the python program
How does python call java classes
How does python import dependency packages
How does python enter interactive mode
How does Python generate xml files
How Python implements the timer function
How to view the python module
How does python determine prime numbers
How does python call its own function
How to learn the Python time module
How does python distinguish return and yield
How to get started quickly with Python
How does Python call cmd using OS modules
How to use the round function in python
How to use the zip function in Python
What does the tab key in python mean
How to use the format function in python
How to enter python through the command line
How about learning python at the age of 27?
How to switch the hosts file using python
How to install the downloaded module in python
Python how to move the code collectively right
Python is short-what does the spirit cage say
How does Python store data to json files