This article mainly introduces the usage of the Print function in Python3.2 and analyzes in detail the Print function Output Techniques in Python3.2 in the form of examples, which has some reference value, for more information about how to use the Print function in Python3.2, see the following example. Share it with you 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 printf in C Language
>>> strHello = "the length of (%s) is %d" %('Hello World',len('Hello World'))>>> print (strHello)the length of (Hello World) is 11
3. formatted and output hexadecimal, decimal, and octal integers
# % X --- hex hexadecimal
# % D --- decimal
# % O --- oct octal
>>> nHex = 0xFF>>> print("nHex = %x,nDec = %d,nOct = %o" %(nHex,nHex,nHex))nHex = ff,nDec = 255,nOct = 377
4. format the 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. format the output floating point number (float)
>>> precise = 3>>> print ("%.3s " % ("python"))pyt>>> precise = 4>>> print ("%.*s" % (4,"python"))pyth>>> print ("%10.3s " % ("python")) pyt
6. 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 feed
Print automatically adds a carriage return at the end of the row. If you do not need to press enter, you only need to add a comma (,) at the end of the print statement to change its behavior.
>>> for i in range(0,6): print (i,) 012345
Or directly use the following function for output:
>>> import sys>>> sys.stdout.write('Hello World')Hello World
I hope this article will help you with Python programming.