📜  如何获取数字的每个数字 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:51.976000             🧑  作者: Mango

代码示例2
sumOfDigit(n):
    sum = 0
    temp = 0
    while n >= 1:
        # temmp % 10 to get the rightmost digit
        temp =  n % 10
        sum += temp
        # n // 10 to get the the rest of digit except rightmost digit (198 // 10 = 19)
        n //= 10