+ 1
What is the difference between str.isdigit, str.isdecimal and str.isnumeric? 🐍
Strings had 3 methods: isdigit, isdecimal and isnumeric. What is their difference? Pure sense said that the difference is that isdecimal checks for decimal numbers and isdigit checks only for digits, but it seems, that it's not true. They all returned False for numbers, that were negative or decimal numbers: https://code.sololearn.com/cO86sgd4u23l/?ref=app
5 Respostas
+ 1
The difference is on how the methods handle other types numbers than basic 0, 1, 2, 3,... 9, examples:
Exponenting marks ¹, ², ³ are only True for isnumeric and isdecimal, but not for isdigit.
Rational marks ¼, ½, ¾ are only True for isnumeric, but not for isdecimal or isdigit.
When isdigit or isdecimal is True, isnumeric is also True.
Their difference will appear during testing the method for thousands of different characters:
https://code.sololearn.com/cyVT6qoELvo4/#py
+ 1
Was I supposed to escape the dot? Like this?:
"5\.6".isdecimal()
Anyways this also returned False.
+ 1
I did not find any difference between those methods. I created that code to prove it.