Home > Backend Development > Python Tutorial > What is the usage of python print

What is the usage of python print

藏色散人
Release: 2020-10-10 10:40:00
Original
47039 people have browsed it

python print is a common function used for printing output. Its usage syntax is "print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False )".

What is the usage of python print

Recommended: "Python Tutorial"

Python print() function

Description

The print() method is used to print output, the most common function.

The flush keyword parameter was added in Python 3.3.

print is a function in Python3.x, but it is not a function in Python2.x, just a keyword.

Syntax

The following is the syntax of the print() method:

print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
Copy after login

Parameters

objects -- plural, indicating that multiple objects can be output at one time. When outputting multiple objects, they need to be separated by ,.

sep -- Used to separate multiple objects. The default value is a space.

end -- used to set the ending. The default value is the newline character \n, we can change it to other strings.

file -- The file object to be written.

flush -- Whether the output is cached is usually determined by the file, but if the flush keyword argument is True, the stream will be forced to be flushed.

Return value

None.

Example

The following shows an example of using the print function:

Test under Python3

>>>print(1)  
1  
>>> print("Hello World")  
Hello World  
 
>>> a = 1
>>> b = 'runoob'
>>> print(a,b)
1 runoob
 
>>> print("aaa""bbb")
aaabbb
>>> print("aaa","bbb")
aaa bbb
>>> 
 
>>> print("www","runoob","com",sep=".")  # 设置间隔符
www.runoob.com
Copy after login

The effect of using the flush parameter to generate a Loading:

Example

import time
print("---RUNOOB EXAMPLE : Loading 效果---")
print("Loading",end = "")
for i in range(20):
    print(".",end = '',flush = True)
    time.sleep(0.5)
Copy after login

The above is the detailed content of What is the usage of python print. 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