Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
communitycreator

What is the String isdigit() method in Python?

Maria Elijah

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.

String isdigit() method

The isdigit() method is a built-in method in python for string handling. This method checks if the given string contains just digits such as 0123456789.

Note: Exponents, like ², are also considered to be digits.

Syntax

string.isdigit()

Parameter

The method isdigit() takes no parameters.

Return value

The isdigit() method returns true if all characters in the string are digits. Otherwise, it returns false.

Code

The following code shows how to use the isdigit() method in python:

# Python code to check whether the String
# consist of digit only
x = '458235001'
print(x.isdigit())
x = '\u0030243abir302'
print(x.isdigit())
# x = '²3447'
# subscript is a digit
x = '\u00B23447'
print(x.isdigit())
# x = '½'
# A fraction is not digit
x = '\u00BD'
print(x.isdigit())

Note:

  • “\u0030” is Unicode for 0
  • “\u00B2” is Unicode for ²
  • ‘\u00BD’ is Unicode for ½

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