小编Fri*_*che的帖子

在Python中,如何计算字符串或整数中的尾随零?

我正在尝试编写一个函数,它返回字符串或整数中的尾随0的数量.这是我正在尝试的,它没有返回正确的值.

def trailing_zeros(longint):
    manipulandum = str(longint)
    x = 0
    i = 1
    for ch in manipulandum:
        if manipulandum[-i] == '0':
            x += x
            i += 1
        else:
            return x
Run Code Online (Sandbox Code Playgroud)

python string

11
推荐指数
3
解决办法
8716
查看次数

标签 统计

python ×1

string ×1