This example describes the use of the print function in Python3.2. Share to everyone for your reference. The specific analysis is as follows:
1. Output string
>>> Strhello = ' Hello World ' >>> print (Strhello) Hello World
2. Format the output integer
Supports parameter formatting, similar to the C-language printf
>>> Strhello = "The length of (%s) is%d"% (' Hello World ', Len (' Hello World ') >>> print (Strhello) the Len Gth of (Hello World) is 11
3. Formatted output 16 binary, decimal, octal integer
#%x---hex hex
#%d---Dec decimal
#%o---Oct octal
>>> Nhex = 0xff>>> print ("Nhex =%x,ndec =%d,noct =%o"% (nhex,nhex,nhex)) Nhex = Ff,ndec = 255,noct = 3 77
4. Formatted output floating-point number (float)
Import math>>> print (' pi=%f '%math.pi) pi=3.141593>>> print ("PI =%10.3f"% math.pi) PI = 3.142> >> print ("PI =%-10.3f"% math.pi) pi = 3.142 >>> print ("PI =%06d"% int (math.pi)) pi = 000003
5. Formatted output floating-point number (float)
>>> precise = 3>>> print ("%.3s"% ("Python")) pyt>>> precise = 4>>> print ("%.*s"% ( 4, "Python")) pyth>>> print ("%10.3s"% ("Python")) PYT
6. Output lists (list)
Output list
>>> lst = [1,2,3,4, ' Python ']>>> print (LST) [1, 2, 3, 4, ' Python ']
Output dictionary
>>> d = {1: ' A ', 2: ' B ', 3: ' C ', 4: ' d '}>>> print (d) {1: ' A ', 2: ' B ', 3: ' C ', 4: ' d '}
7. Automatic line Wrapping
Print automatically adds a carriage return at the end of the line, and if you don't need a carriage return, simply add a comma "," at the end of the print statement to change its behavior.
>>> for I in Range (0,6): print (i,) 012345
Or simply use the following function to output:
>>> Import sys>>> sys.stdout.write (' Hello World ') Hello World
Hopefully this article will help you with Python programming.