Python isdigit is one of the Python String Method which is used check whether the character is digit or not. In this article we will show you, How to write isdigit Function in Python Programming with example.
Python isdigit Syntax
The basic syntax of is digit in Python function is as shown below:
String_Value.isdigit()
- String_Value: Please select a valid String literal.
isdigit function will return a Boolean value as output.
- If the String_Value is a valid digit then it will return TRUE
- If the String_Value is not a valid digit then the function will return FALSE
Program to Check for Digit using Python isdigit function
The following set of examples will help you understand the isdigit function and how to use it.
# Python isdigit Method Example Str1 = '123456789'; print('First Output of a isdigit() method is = ', Str1.isdigit()) Str2 = ' '; print('Output of a isdigit() method For Empty Space is = ', Str2.isdigit()) # Performing isdigit() function directly Str3 = 'Find Tutorial at Tutorial Gateway'.isdigit() print('Second Output of a isdigit() method is = ', Str3) # Performing isdigit() on both Digits and Alphabets Str5 = '123456789a'.isdigit() print('Third Output of a isdigit() method is = ', Str5) # Performing isdigit() on Float values Str6 = '1234.67'.isdigit() print('Fourth Output of a isdigit() method is = ', Str6) # Performing isdigit() on Negative Values Str7 = '-1234'.isdigit() print('Fifth Output of a isdigit() method is = ', Str7)
OUTPUT
ANALYSIS
First we declared the String variable Str1 and assigned corresponding value (Integer Value) using following statement. Next, we used the isdigit() function to check whether the string is digit or not. As you can see, it is a valid digit so, function will return TRUE
Str1 = '123456789'; print('First Output of a isdigit() method is = ', Str1.isdigit())
The following statement will check whether the Empty space is a valid digit or not
Str2 = ' '; print('Output of a isdigit() method For Empty Space is = ', Str2.isdigit())
Next, we are using the isdigit function in python on group of words
Str3 = 'Find Tutorial at Tutorial Gateway'.isdigit() print('Second Output of a isdigit() method is = ', Str3)
Thank you for Visiting Our Blog