Reputation: 518
Can anyone explain the following to me please.
i = 700001 z = str(i % 100000)
z='1', but i want to z='00001'. How i can get it?
Upvotes: 1
Views: 149
Reputation: 17636
See Python string formatting:
z = '%05d'%(i % 100000)
Upvotes: 2
Reputation: 59583
Use str.rjust
str.rjust
>>> s = '1' >>> s.rjust(5, '0') '00001'
Reputation: 336408
Another solution:
>>> z.zfill(5) '00001'
Upvotes: 4
Reputation: 185972
Do this:
z = '{:05}'.format(i % 100000)
Upvotes: 6