isdigit() in Python

Overview
Python isdigit() function is an inbuilt method for string handling. It is used to check whether all the string characters are digits(from 0 to 9) or not. This function doesn't take any parameters. This function is used on strings and returns a boolean value based on conditions.
Syntax of isdigit() function in python
The syntax for isdigit() function in Python:
Transform Your Career
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
Parameter of isdigit() function in python
This function doesn't take any parameters.
Return Value of isdigit() function in python
Return Type: <bool>
This function returns the boolean value based on the situation. isDigit() returns True if all the string characters are digits. Else it returns False.
If the string is empty, it means that string has no digit inside it, so it will also return False.
Exceptions of isdigit() function in python
- As isdigit() does not take any arguments. Therefore it raises an error if a parameter is passed.
- Roman numbers and fractions are not considered digits, so that it will return False if this function is used on these kinds of strings.
Example of isdigit() function in python
As discussed in the above section, check whether the phone number entered by the employee is correct or not. Now, let's implement that part to understand more about isDigit().
Code:
Output:
Turn Learning into Career Growth
What is isDigit() function in python?
Let's think of a situation where you have created a form for taking the phone number of the employees. Now, you have to check whether the entered number is a valid number or not. isDigit() function of python is the best way to handle this problem. isDigit() is an inbuilt function of python which is used to check whether all characters of strings are digit or not. Read along to know more about the working of isDigit().

More Examples
Example 1: Working of isDigit()
As we understood above, isdigit() does not take any parameter. It is just used with string to check whether every character of the string is a digit.
Here we will write the code to check if the pin code entered by the user is valid or not.
Code:
Output:

Example 2: String Containing digits and Numeric Characters
Here we will write a code to check isdigit() with different types of strings.



Code:
Output:
Scaler Placement Report and Statistics
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
Conclusion
- isDigit(), the inbuilt function of python is used to check whether each and every character of the string is a digit or not.
- isDigit() doesn't takes any parameter.
- It returns a true value only if all the string characters are digits. Else, in every other condition, it returns false.