New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
str is number methods don't recognize '.' #62940
Comments
Shouldn't at least isdecimal return True? >>> '123.0'.isdecimal()
False
>>> '123.0'.isalnum()
False
>>> '123.0'.isnumeric()
False
>>> '123.0'.isdigit()
False |
isdecimal() is working as documented, isn't it? A period character serving as a decimal point is not the same as a decimal character. "Return true if all characters in the string are decimal characters and there is at least one character, false otherwise. Decimal characters are those from general category “Nd”. This category includes digit characters, and all characters that can be used to form decimal-radix numbers, e.g. U+0660, ARABIC-INDIC DIGIT ZERO." |
Ned is right, everything is working as documented and intended: as a way to avoid using a regex to test a simple case instead of trying to do anything fancy like identify a number. |
I get the same resluts if I make the string by str(123.0). I was thinking it should test True for the isdecimal case for that. It seems I missunderstood their purpose/use. This seems like it would be a very common misunderstanding. It appears, (Because it isn't stated in the doc strings), that they are for testing what specific sub-group of unicode data, the individual character(s) are in. I think the methods doc strings should say this and be worded so they are more character specific. """ Tests each character, and returns true if As for testing weather or not a string as a whole represents a number value, it seems try/except is still the best way. :-/ |
Feel free to submit an issue suggesting better docstrings as that sounds like it could stand to get some TLC. |
|
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: