Answers for "python get number length"

4

how to find length of number in python

len(str(133))
Posted by: Guest on May-19-2020
0

get length of an integer python

# Below uses constant space (converting to string and then gettings it's length does not)
num = 12362
count = 0
while num > 0:
  count += 1
  num = num // 10
print(count)

# for negative numbers, take absolue value first:
num = -12362
num = abs(num)
count = 0
while num > 0:
  count += 1
  num = num // 10
print(count)
Posted by: Guest on June-28-2021

Python Answers by Framework

Browse Popular Code Answers by Language