The python string isdigit() method is used to check whether the string consists of digits. This method returns true if all the characters in the input string are digits and there is atleast one character. Otherwise, it returns false.
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. ,,,,,, are Kharosthi numbers. Formally, a digit is a character that has the property value Numeric_Type=Digit or Numeric_Type=Decimal.
Let us look into this method with more details in the following section.
SyntaxFollowing is the syntax for the python string isdigit() method −
str.isdigit()Parameters
The python string isdigit() method doesnot contain any parameters.
Return ValueThe python string isdigit() method returns true if all characters in the string are digits and there is at least one character and false otherwise.
ExampleThe following is an example of the python string isdigit() method. In this program, a string "1235" is created and the isdigit() method is invoked.
str = "1235" result=str.isdigit() print("Are all the characters of the string digits?", result)
On executing the above program, the following output is generated -
Are all the characters of the string digits? TrueExample
In the python string isdigit() method, the digits also include the kharosthi numbers which are ,,,,,,.
str = "" result=str.isdigit() print("Are all the characters of the string digits?", result)
The following is the output obtained by executing the above program -
Are all the characters of the string digits? TrueExample
The superscripts of numbers in unicode representation are also considered as digits by this isdigit() method.
str = "\u00B3" #superscript of 3 result=str.isdigit() print("Are all the characters of the string digits?", result)
The following output is obtained by executing the above program -
Are all the characters of the string digits? TrueExample
The isdigit() method considers unicode representation of numbers as digits only.
str = "\u0030" #unicode for 0 result=str.isdigit() print("Are all the characters of the string digits?", result)
The above program, on executing, displays the following output -
Are all the characters of the string digits? TrueExample
The fractions are not considered as digits. So, if the created string contains fractions in unicode format or any other format, the method returns false.
str = "\u00BE" #unicode for fraction 3/4 result=str.isdigit() print("Are all the characters of the string digits?", result)
The output of the above program is displayed as follows -
Are all the characters of the string digits? False
python_strings.htm
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4