【发布时间】:2020-08-05 18:35:17
【问题描述】:
我正在尝试将 python 脚本放在运行 micro python 的 pyboard 上。在 MicroPython 中是否有 .zfill 的 python 等效项?
【问题讨论】:
标签: micropython
我正在尝试将 python 脚本放在运行 micro python 的 pyboard 上。在 MicroPython 中是否有 .zfill 的 python 等效项?
【问题讨论】:
标签: micropython
没有内置 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)
这可能对您有用吗?只需传递您需要的字符串和字符串宽度。
【讨论】:
欢迎来到!
不,MicroPython 在字符串上没有 zfill 方法。
如果您正在寻找一个特定的宽度,您需要获取一个 len(str),然后将所需的“0”字符串连接到字符串的开头。
【讨论】: