In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you what the function of print in Python is. The content is concise and easy to understand. It can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
Print (* objects, sep='', end='\ ntext, file=sys.stdout, flush=False) prints the objects to the text stream specified by file, separated by sep and end at the end. Sep, end, file and flush, if present, must be given in the form of keyword arguments.
All non-keyword arguments are converted to strings, just as if str () was executed, and are written to the stream, sep with end at the end. Both sep and end must be strings; they can also be None, which means using default values. If no objects is given, print () will only write to end.
The file parameter must be an object with a write (string) method; if the parameter does not exist or is None, sys.stdout is used. Because the parameters to be printed are converted to text strings, print () cannot be used for file objects in binary mode. For these objects, you should use file.write (...) instead.
Whether the output is cached or not is usually determined by file, but if the flush keyword parameter is true, the stream is forced to refresh.
Changed in version 3. 3: the flush keyword parameter was added.
Of course, it is not enough to read the document, we need to practice the code according to the explanation of the parameters inside. We can first test each parameter individually, and then combine the various parameters to practice.
See * objects, parameters in this format can generally represent some columns of data. Can be empty, can be more than one. The next few parameters can be modified according to the meaning. A special one is file, which, as its name implies, prints to a file, while print is most commonly used to output content to the console, which is kept by default.
Here are a few examples:
In [1]: print () # null value, default line feeds
In [2]: print ('hello',' de8ug') # two strings
Hello de8ug
In [3]: print ('hello',' de8ug', sep='-') # modify string delimiter
Hello-de8ug
In [4]: print ('hello',' de8ug', end='-') # modify end symbol
Hello de8ug-
In [5]: print ('hello',' de8ug', flush=True) # flush test, it doesn't seem to work. Look down at the progress bar example
Hello de8ug
In [6]: import time
In [7]: for i in range (8): # simple progress bar
...: print ('\ ritual end='%', flush=True I, end='%', flush=True) #'\ r' indicates enter, move the cursor to the beginning of the line, and then refresh it with the flush.
...: time.sleep (1)
...:
7% # you will see a change from 0 to 7
In [8]: def progress (percent=0, width=30): # complex progress bar, set # and the total width of spaces according to the parameters, then add # and modify the% number
...: left = width * percent / / 100
...: right = width-left
: print ('\ r [','#'* left,'* right,']'
...: f'{percent:.0f}%'
...: sep='', end='', flush=True)
...:
In [9]: for i in range (101):
...: progress (I)
: time.sleep (0.1)
...:
[# #] 100%
The above is what is the function of print function in Python. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.