In Python, isnumeric() is a built-in method used for string handling. The issnumeric() methods returns “True” if all characters in the string are numeric characters, Otherwise, It returns “False”.
This function is used to check if the argument contains all numeric characters such as : integers, fractions, subscript, superscript, roman numerals etc.(all written in unicode)
string.isnumeric() Parameters: isnumeric() does not take any parameters Returns : 1.True- If all characters in the string are numeric characters. 2.False- If the string contains 1 or more non-numeric characters.
Input : string = '1889345' Output : True Input : string = '\u00BD' Output : True Input : string = '123ayu456' Output : False
Errors and Exceptions
- It does not contain any arguments, therefore, it returns an error if a parameter is passed.
- Whitespaces are not considered to be numeric, therefore, it returns “False”
- Subscript, Superscript, Fractions, Roman numerals (all written in unicode)are all considered to be numeric, Therefore, it returns “True”
Application : Given a string in python, count number of numeric characters in the string and remove them from the string and print the string.
Input : string = '123geeks456for789geeks' Output : 9 geeksforgeeks Input : string = '123ayu456' Output : 6 ayu
1. Initialise an empty newstring and variable count to 0.
1. Traverse the given string character by character upto its length, check if character is a numeric character.
2. If it is a numeric character, increment the counter by 1 and do not add it to the new string, else traverse to the next character and keep adding the characters to the new string if not numeric.
3. Print the value of the counter and the newstring.
9 geeksforgeeks 6 ayu
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- numpy string operations | isnumeric() function
- Python String isspace() and its application
- Python String isalpha() and its application
- Python String isdigit() and its application
- Build an Application to Search Installed Application using Python
- divmod() in Python and its application
- isprintable() in Python and its application
- Login Application and Validating info using Kivy GUI and Pandas in Python
- Profile Application using Python Flask and MySQL
- Build an Application to extract URL and Metadata from a PDF using Python
- Python String index() and its applications
- Birthday Reminder Application in Python
- Python | Create simple animation for console-based application
- English dictionary application using Python
- Python | ToDo GUI Application using Tkinter
- Hierarchical treeview in Python GUI application
- Create First GUI Application using Python-Tkinter
- GUI chat application using Tkinter in Python
- Python VLC Instance - Setting Application Name
- Python VLC Instance - Setting Meta Data of Application
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : dtf112