×

Python String isdigit() method

Python String isdigit() method

The string.isdigit() method returns a boolean value true if all characters in the string are digits else for any other value it returns false.

Syntax

string.isdigit()

Parameter

NA

Return

This method returns a Boolean value true if all characters in the string are digits else for even one non-digit character it returns False.

Example 1

 # Python program explaining
 # the isdigit() method
 # initializing the string value
 strVal = "50800"
 # checking whether the passed string is a digit or not
 result = strVal.isdigit()
 # printing the isdigit() result
 print("The isdigit() method returns: ",result) 

Output

The isdigit() method returns:  True

Example 2

 # Python program explaining
 # the isdigit() method
 # initialising the string value
 strVal = "M0n1caG3ll3r"
 print("String 1:",strVal)
 # validating if and else condition
 if strVal.isdigit() == True:
    print("All characters of specified string are digits.")
 else:
     print("All the characters are not digits.")
 # passing another string
 strVal1="123234675"
 print("String 2:",strVal1)
 # again validating if and else condition
 if strVal1.isdigit() == True:
    print("All characters of specified string are digits.")
 else:
     print("All the characters are not digits.") 

Output

 String 1: M0n1caG3ll3r
 All the characters are not digits.
 String 2: 123234675
 All characters of specified string are digits. 

Example 3

 # Python program explaining
 # the isdigit() method
 strVal1 = '23455'
 print(strVal1.isdigit())
 #s = '²3455'
 # subscript is a digit
 strVal2 = '\u00A223455'
 print(strVal2.isdigit())
 # s = '½'
 # fraction is not a digit
 strVal3 = '\u00BD'
 print(strVal3.isdigit())
 #passing special characters in the string 
 strVal4 = '!@9876/0'
 print(strVal4.isdigit()) 

Output

 True
 False
 False
 False 

Related Topics

Python Interpreter

In this tutorial, we will go through the basic knowledge about what an interpreter is and how we use it in the python programming language. It is one of the...

3 minutes read.

Gaussian elimination in python

Linear and polynomial equations are used in almost all fields of numerical simulation. However, its most common use in engineering is in the area of linear system analysis. The broader...

3 minutes read.

Python Time Module

Python contains many files that can be imported into a python code and used whenever we want. One of that modules is the time module. It is a good practice...

6 minutes read.

Python for Data Analysis

Data analysis uses various techniques to read, illustrate, manipulate and evaluate a particular data. You can have access to the data and keep the data updated regularly. You can append...

4 minutes read.

chr() and ord() Functions in Python

Python language contains many built-in functions which we use for many programs to work efficiently. The chr() and ord() are a few built-in functions in Python that are used for...

4 minutes read.

SKLearn Linear Module

The SK learn linear module is one such module that helps to study the relationship between the independent and dependent variables.The linear module can be implemented by using the best...

3 minutes read.

Python Algorithms

A quote goes, "A goal without a plan is just a wish." To achieve anything in life, we can't simply go for it without making a plan and sticking to...

4 minutes read.

Expressions in Python

What is Expression in Python? The expression contains more than one operator as well as the operands with it. Expression helps us to produce some other values. In the Python programming...

12 minutes read.

Bar Plot in Python

A bar chart or bar graph displays categorical data using rectangular bars with heights or lengths proportionate to the values for the data distributed in the dataset. In a bar...

16 minutes read.

Python zip() Function

Python zip() Function The zip() function makes an iterator that aggregates elements from each of the iterables and returns an iterator of tuples. Syntax zip(*iterables) Parameter iterables: Iterator objects that will be joined together Return This function...

1 minute read.

Import py file in Python

In Python programming language, a module is a single layer of block of Python code that can be loaded and used by importing into other Python block of code. A module...

4 minutes read.

Applications of Python

Top 10 Applications of Python in 2020- 2021 Python language is famous for its general-purpose nature, which enables developers to use it in every field of development. Python can be found...

6 minutes read.

Python Packages

A package is a collection of Python modules that share a similar namespace and are generated by putting all of the modules in a single directory with certain special files...

6 minutes read.

How to Add Elements in List in Python?

How to Add Elements in List in Python We all are aware of the wide spectrum of applications where the data structures of Python are used. Be it lists, tuples, or...

4 minutes read.

Python Modules List

Python is like an ocean. If you have been working with Python, you might’ve already heard the word module. When we solve a problem in mathematics, there will be several...

3 minutes read.

Salary of Python Developers in India

In this tutorial, we will understand who python developers are and what is their salary when they work in India. Python Developers Python Developers are the people who are involved in designing...

4 minutes read.

Python Operator Precedence

Before knowing about the operator precedence in Python, we have to know about the operators in Python. So let's have a look at it. According to one definition, the operator is...

3 minutes read.

Python String rstrip() method

Python String rstrip() method The string.rstrip() method in Python returns a copy of the string with trailing characters removed. Syntax string.rstrip([chars]) Parameter chars:  This argument represents a string specifying the set of characters to be...

1 minute read.

Python Strong Number

Strong Number- Logic Divide each of the number's digits into separate units to determine if it is a strong number or not.The factorial of each digit must then be determined. The...

5 minutes read.

Linear Regression using Sklearn with Example

This article will examine Python's global, local and non-local variables and show you how to use them to write code without problems. Let's quickly review what a variable in Python is...

8 minutes read.