How do I turn the number 120 to 00120 in python?

  • Context: Python 
  • Thread starter Thread starter vorcil
  • Start date Start date
  • Tags Tags
    Python
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 2K views
vorcil
Messages
395
Reaction score
0

Homework Statement



I need to know how to change the format of a number in python

for example if I have a integer variable, xstart=0.
If i were to print(xstart) I want it to show 00000
and if I were to add 120 to xstart
xstart+=120
then print it
print(xstart) I want it to show 00120

Thanks.

Homework Equations





The Attempt at a Solution

 
Physics news on Phys.org
You mean something like this?

print('%05d' % xstart)

It is possible to look these things up. That would be a good skill to acquire.
 
Last edited: