The python string isnumeric() method is used to check whether the string consists of numeric characters. This method returns true if all the characters in the input string are numeric and there is atleast one character. Otherwise, it returns false.
The numeric characters include digit characters, and all characters that have the Unicode numeric value property, e.g. U+2155, VULGAR FRACTION ONE FIFTH. Formally, numeric characters are those with the property value Numeric_Type=Digit, Numeric_Type=Decimal or Numeric_Type=Numeric.
In the following section, let us look into this method with more details.
SyntaxFollowing is the syntax for the python string isnumeric() method −
str.isnumeric()Parameters
The python string isnumeric() method doesnot contain any parameters.
Return ValueThe python string isnumeric() method returns true if all characters in the string are numeric and there is at least one character and false otherwise.
ExampleThe following is an example of the python string isnumeric() method. In this program, we are trying to find whether the string "Welcome2023" is alpha numeric.
str = "Welcome2023" result=str.isnumeric() print("Are all the characters of the string numeric?", result)
On executing the above program, the following output is generated -
Are all the characters of the string numeric? FalseExample
let us see another example -
str = "2023" result=str.isnumeric() print("Are all the characters of the string numeric?", result)
The following is the output obtained by executing the above program -
Are all the characters of the string numeric? TrueExample
The unicode representation of numbers are also considered as numeric by the isnumeric() method.
str = "\u0030" #unicode for 0 result=str.isnumeric() print("Are all the characters of the string numeric?", result)
The following output is obtained by executing the above program -
Are all the characters of the string numeric? TrueExample
The python string isnumeric() method considers unicode representation of fractions as numeric only.
str = "\u00BE" #unicode for fraction 3/4 result=str.isnumeric() print("Are all the characters of the string numeric?", result)
The above program, on executing, displays the following output -
Are all the characters of the string numeric? TrueExample
The Kharosthi numbers such as ,,,,,, are considered as numeric. So, the python string isnumeric() method returns true.
str = "" result=str.isnumeric() print("Are all the characters of the string numeric?", result)
The output of the above program is displayed as follows -
Are all the characters of the string numeric? True
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