I am trying to put a python script on a pyboard that’s running micro python. Is there a python equivalent of .zfill In MicroPython?
Asked
Active
Viewed 1,509 times
2 Answers
5
there is no inbuilt zfill but I use this zfl function
def zfl(s, width):
# Pads the provided string with leading 0's to suit the specified 'chrs' length
# Force # characters, fill with leading 0's
return '{:0>{w}}'.format(s, w=width)
This might be useful to you? Just pass the string and the string width you require.
0
welcome to SO!
No, MicroPython does not have a zfill method on strings.
If you're looking for a specific width, you'll need to get a len(str) and then concatenate the desired string of "0"s to the start of string.

Patrick
- 2,044
- 1
- 25
- 44