get digits of number python code example
Example 1: python sum of digits
def sum_digits(n):
s = 0
while n:
s += n % 10
n //= 10
return s
Example 2: number of digits in a number python
n = 1234 //Any Random Number
digits = len(str(n)) //Saves the number of digits of n into the variable digits