+ 1

How to count the digits of a number that starts with zero ?

I want to count the digits of a number like ( 010 ) in python. How should I do that?

22nd Nov 2021, 7:38 PM
Nikki
3 Respostas
+ 7
Nikki #to get the number of digits e.g. '010' can be done like: str_num = input() if str_num.isdigit(): # check if the string contains only digits: print(len(str_num)) # get the number of digits:
22nd Nov 2021, 9:51 PM
Lothar
Lothar - avatar
+ 8
Nikki , for your example '010', do want to count the leading zero or not?
22nd Nov 2021, 9:07 PM
Lothar
Lothar - avatar
0
Lothar , I want to count the zero too .
22nd Nov 2021, 9:13 PM
Nikki