SoFunction
Updated on 2024-11-17

Print output in python

1. Ordinary output:

print(str)# str is any string, number ---

2. Format the output:

 print('1,2,%s,%d'%('asd',4))
1,2,asd,4

Somewhat similar to C

3. Other:

>>> pi = 3.141592653 
>>> print('%10.3f' % pi) # Field width 10, precision 3
   3.142 
>>> print("pi = %.*f" % (3,pi)) # Use * to read field widths or precision from a trailing tuple
pi = 3.142 
>>> print('%010.3f' % pi) # Fill in the blanks with zeros
000003.142 
>>> print('%-10.3f' % pi) # Left-aligned
3.142    
>>> print('%+f' % pi) #Display plus and minus signs
+3.141593

Here's a look at describing the print() function in python

The print() method is used to print output, one of the most common functions.

print in is a function, but in the version is not a function, just a keyword.

grammatical

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

print(*objects, sep=' ', end='\n', file=)

parameters

objects -- plural, meaning that multiple objects can be output at once. When outputting multiple objects, you need to separate them with ,.
sep -- Used to space multiple objects, the default value is a space.
end -- Used to set what to end with. The default value is the newline character \n, which we can replace with another string.
file -- The file object to write to.

summarize

The above is a small introduction to the python print() output and function usage ,hope to help you, if you have any questions please leave me a message, I will reply to you in time. Here also thank you very much for your support of my website!
If you find this article helpful, please feel free to reprint it, and bother to cite the source, the