is there any function to directly find greatest digit in a number in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

is there any function to directly find greatest digit in a number in python

4th Sep 2020, 12:14 PM
Jeet Swarnakar
Jeet Swarnakar - avatar
4 Answers
+ 2
You can convert to string, then to list and use the max function, like this: num = 75482953 print(max(list(str(num)))) Its return 9
4th Sep 2020, 1:03 PM
Nathan Sikati
Nathan Sikati - avatar
+ 7
Nathan Sikati You don't need to convert to a list. max() works on strings too. print(max(str(num))) gives the same result. If you are just entering numbers, print(max(input())) works 🙂
5th Sep 2020, 8:14 AM
David Ashton
David Ashton - avatar
+ 3
There's nothing like that. You need to break it down to individual digits, and then compare digit by digit. You can refer the link below https://www.google.com/amp/s/www.geeksforgeeks.org/largest-and-smallest-digit-of-a-number/amp/
4th Sep 2020, 12:33 PM
Charitra
Charitra - avatar
+ 1
David Ashton i tried it, its works. Thanks👍
5th Sep 2020, 11:41 AM
Nathan Sikati
Nathan Sikati - avatar