id number zero python

Solutions on MaxInterview for id number zero python by the best coders in the world

showing results for - "id number zero python"
Elena
02 Jan 2020
1>>> f'{5:04}'
2'0005'
3
4>>> f'{5:04}'
5'0005'
6
7#This uses the string formatting minilanguage:
8>>> five = 5
9>>> f'{five:04}'
10'0005'
11
12#The first zero means the fill, the 4 means to which width:
13>>> minimum_width = 4
14>>> filler = "0" # could also be just 0
15>>> f'{five:{filler}{minimum_width}}'
16'0005'
17
18#Next using the builtin format function:
19>>> format(5, "04")
20'0005'
21>>> format(55, "04") 
22'0055'
23>>> format(355, "04")
24'0355'
25
26#Also, the string format method with the minilanguage:
27>>> '{0:04}'.format(5)
28'0005'
29
30#Again, the specification comes after the :, and the 0 means fill with zeros and the 4 means a width of four.
31#Finally, the str.zfill method is custom made for this, and probably the fastest way to do it:
32>>> str(5).zfill(4)
33'0005'
similar questions
queries leading to this page
id number zero python