micro python中有Zfill类型的函数吗?微型 python 中的 Zfill

Gre*_*tts 2 micropython

我正在尝试将 python 脚本放在运行 micro python 的 pyboard \xe2\x80\x99s 上。MicroPython 中是否有相当于 .zfill 的 python 版本?

\n

小智 5

没有内置的 zfill 但我使用这个 zfl 函数

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)
Run Code Online (Sandbox Code Playgroud)

这可能对你有用?只需传递您需要的字符串和字符串宽度即可。