count digits from number using python

In this example, you will learn to get the input from the user then count number of digits from user inputted number and finally print out the result.

Example 1 : Using While Loop

    
#Python Program to Count Digits From Number
count = 0
number = int(input("Enter a number :: "))

while (number > 0):
    number = number//10
    count = count + 1

print("Total number of digits : ", count)
       

Output :

    
Enter a number :: 123569
Total number of digits :  6
    

Example 2 : Using in-built methods

    
#Python program to count digits from number using in-built methods
count = 0
number = int(input("Enter a number :: "))

print("Total number of digits : ", len(str(abs(number))))
       

Output :

    
Enter a number :: 1234569
Total number of digits :  7
    

Share your thoughts

Ask anything about this examples