【问题标题】:Is there a Zfill type function in micro python. Zfill in micro python微型 python 中是否有 Zfill 类型的函数。微型python中的zfill
【发布时间】:2020-08-05 18:35:17
【问题描述】:

我正在尝试将 python 脚本放在运行 micro python 的 pyboard 上。在 MicroPython 中是否有 .zfill 的 python 等效项?

【问题讨论】:

    标签: micropython


    【解决方案1】:

    没有内置 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)
    

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

    【讨论】:

      【解决方案2】:

      欢迎来到!

      不,MicroPython 在字符串上没有 zfill 方法。

      如果您正在寻找一个特定的宽度,您需要获取一个 len(str),然后将所需的“0”字符串连接到字符串的开头。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-11-11
        • 2021-06-05
        • 2021-04-18
        • 1970-01-01
        • 2023-01-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多