0

Why do integers not have a len()?

3rd Nov 2018, 1:03 PM
Bobur Ochilov
Bobur Ochilov - avatar
6 Answers
+ 4
Having a len() doesn't make too much sense, the len() function is usually for collections such as lists and sets because there’s multiple elements, if you want to count the number of digits in a number you could use a while loop like so... https://code.sololearn.com/c8hj9POITmwY/?ref=app
3rd Nov 2018, 1:21 PM
TurtleShell
TurtleShell - avatar
+ 1
Bobur Ochilov I updated the answer, I would put that code in a reusable function
3rd Nov 2018, 1:25 PM
TurtleShell
TurtleShell - avatar
+ 1
Bobur Ochilov simple. len(str(1253)) or num = 2927 num_of_digits = 0 while num : num //= 10 num_of_digits += 1 print(num_of_digits)
3rd Nov 2018, 6:02 PM
Roneel
Roneel - avatar
0
And how can I find the number of digits in an integer?
3rd Nov 2018, 1:22 PM
Bobur Ochilov
Bobur Ochilov - avatar
0
Yeeah!!! Of course!
3rd Nov 2018, 1:27 PM
Bobur Ochilov
Bobur Ochilov - avatar
0
Thank you!
3rd Nov 2018, 1:27 PM
Bobur Ochilov
Bobur Ochilov - avatar