Can someone say if "²" is a symbol or a digit? (alt+1277, power of two)
print("²".isdigit())
# True
print("²".isnumeric())
# True
Because Python says it's a digit, but it's not actually a digit. Am I wrong? Or it's a bug?
The Python isalpha() method returns true if a string only contains letters. Python isnumeric() returns true if all characters in a string are numbers. Python isalnum() only returns true if a string contains alphanumeric characters, without symbols.
The isnumeric() method returns True if all the characters are numeric (0-9), otherwise False. Exponents, like ² and ¾ are also considered to be numeric values.
Check if String Contains Only Numbers using isdigit() method Python String isdigit() method returns “True” if all characters in the string are digits, Otherwise, It returns “False”.
Python string isdecimal() Method Python String isdecimal() function returns true if all characters in a string are decimal, else it returns False.
It is explicitly documented as a digit:
str.isdigit()
Return
True if all characters in the string are digits and there is at least one character,
False` otherwise. Digits include decimal characters and digits that need special handling, such as the compatibility superscript digits. This covers digits which cannot be used to form numbers in base 10, like the Kharosthi numbers. Formally, a digit is a character that has the property value Numeric_Type=Digit or Numeric_Type=Decimal.
Regarding Numeric_Type, this is defined by Unicode:
Numeric_Type=Digit
Variants of positional decimal characters (Numeric_Type=Decimal) or sequences thereof. These include super/subscripts, enclosed, or decorated by the addition of characters such as parentheses, dots, or commas.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With