Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13951

How to zero pad an f-string? [duplicate]

$
0
0

Like this is how you can 0 pad a format string

for i in range(10):   zeropad = "Value is{:03}.".format(i)   print(zeropad)

and you get result as

Value is 000Value is 001

and so on...

So, how can i do the same thing with f-strings??

I tried using the .zfill() function, but that doesnt work either

for i in range(1, 11):  sentence = f"The value is {i(zfill(3))}."  print(sentence)`

This gives an error

Traceback (most recent call last):  File "main.py", line 2, in <module>    sentence = f"The value is {i.zfill(3)}."AttributeError: 'int' object has no attribute 'zfill'

Viewing all articles
Browse latest Browse all 13951

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>