Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
communitycreator

What is isdecimal() in Python?

Mahnoor Zaheer

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The isdecimal() function in Python tells whether a string contains all numeric characters.

Syntax

The syntax of the isdecimal() method is as follows:

string.isdecimal()
The syntax of the isdecimal() method in Python

Parameters

The isdecimal() method does not take any parameters.

Return value

isdecimal() returns a boolean value. If the string contains all decimal characters, the function returns True. Otherwise, it returns False.

Code

In the code below, the isdecimal() function returns False when the string contains either all alphabet or alphanumeric characters. However, in the case of a complete numeric string, the method returns True.

# contains all numbers
num = "12345"
print(num.isdecimal())
# contains all alphabets
alpha = "abcdef"
print(alpha.isdecimal())
# contains both alphabets and numbers
alphanum = "abc34de78"
print(alphanum.isdecimal())
Code example of the isdecimal() method in Python

RELATED TAGS

python
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring