Skip to content
Home » Length of integer in Python

Length of integer in Python

Learn about the Length of integer in Python in the below code example. Also, refer to the comments in the code snippet to get a detailed view about what’s actually happening.

Length of integer in Python

If you want to know the length of an integer, as in the number of digits, you can always convert it to string like str(123) and find its length like len(str(123)).

Program:

# Python program to count number of digits in a number

# input
num = int(input('Enter any number: '))

# count number of digits
count = len(str(num))
    
# printing number of digits
print('Number of digits:', count)

Output:

Enter any number: 123
Number of digits: 3

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Code : Python program to count number of digits in a number