+ 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

27th Aug 2019, 9:37 AM
Seb TheS
Seb TheS - avatar
3 odpowiedzi
+ 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
18th Oct 2019, 11:04 AM
Seb TheS
Seb TheS - avatar
+ 1
Was I supposed to escape the dot? Like this?: "5\.6".isdecimal() Anyways this also returned False.
27th Aug 2019, 9:53 AM
Seb TheS
Seb TheS - avatar
+ 1
I did not find any difference between those methods. I created that code to prove it.
27th Aug 2019, 4:04 PM
Seb TheS
Seb TheS - avatar