+ 1
How to formate int in python?
Does anybody know how to print out an integer in two space holders for example like x=2 i want the output to look like this : x=02
4 Answers
+ 4
# You can use f-string format options:
x = 3
print(f'{x:>03}')
# Another way could be using the number as string and then use the string-method zfill()
print(f'{x}'.zfill(3))
+ 3
an other f-string version:
x = 2
print(f"x={x:02d}")
+ 1
Thank you all I've used print("%02d"%x) and it worked also