Format of Python3

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
print('{0},{1}'.format('zhangk'32))
 
print('{},{},{}'.format('zhangk','boy',32))
 
print('{name},{sex},{age}'.format(age=32,sex='male',name='zhangk'))
 
# Format qualifier
# It has a rich "format qualifier" (grammar is {} with: number), for example:
 
# Filling and aligning
# Filling is often used with alignment.
# ^、<、>They are center, left alignment, right alignment, and back width.
# :The character that is filled with the back of the number can only be one character.
 
print('{:>8}'.format('zhang'))
print('{:0>8}'.format('zhang'))
print('{:a<8}'.format('zhang'))
print('{:p^10}'.format('zhang'))
 
# Accuracy and type F
# Accuracy is often used with type F.
print('{:.2f}'.format(31.31412))
 
# Other types
# It is mainly binary, B, D, O, X are binary, decimal, octal, sixteen binary.
print('{:b}'.format(15))
 
print('{:d}'.format(15))
 
print('{:o}'.format(15))
 
print('{:x}'.format(15))
 
# The comma can also be used to make thousands of separators.
print('{:,}'.format(123456789))

  

Leave a Reply

Your email address will not be published. Required fields are marked *