Home > Backend Development > Python Tutorial > Understand the input and output of Python in one article

Understand the input and output of Python in one article

Tomorin
Release: 2018-08-20 10:15:42
Original
1994 people have browsed it

This article introduces the input and output of Python. Since it is Python code, then there must be output, then, PythonHow does output ?

Output

Use print() to add a string in brackets to Output specified text. For example, to output 'hello, world', the code is as follows:

>>> print('hello, world')
Copy after login

print() The function can also accept multiple strings, separated by commas "," If you turn it on, you can connect it into a string and output :

>>> print('The quick brown fox', 'jumps over', 'the lazy dog')
The quick brown fox jumps over the lazy dog
Copy after login

print() will print each string in turn, and when it encounters a comma "," it will be output A space, therefore, The output string of is spelled like this:

Understand the input and output of Python in one article

print() can also be Print integers, or calculation results:

>>> print(300)
300
>>> print(100 + 200)
300
Copy after login

Having said so much output, so what is Python's input?

Input

Now, you can use print() to output the results you want. However, what if you want the user to enter some characters from the computer? Python provides an input() that allows users to enter a string and store it in a variable. For example, enter the user's name:

>>> name = input()
Michael
Copy after login

When you enter

name = input() and press Enter, the Python interactive command line is waiting for your input. At this time, you can enter any characters and press Enter to complete the input.

After the input is completed, there will be no prompts, and

Pythonthe interactive command line returns to the >>> state. So where did the content we just entered go? The answer is stored in the name variable. You can directly enter name to view the variable content:

>>> name
'Michael'
Copy after login
The above is

about the input and output of Python

The above is the detailed content of Understand the input and output of Python in one article. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template