Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Python String isdigit() Method
Next article icon

Python string isdecimal() Method

Last Updated : 30 Dec, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In Python, the isdecimal() method is a quick and easy way to check if a string contains only decimal digits. It works by returning True when the string consists of digits from 0 to 9 and False otherwise. This method is especially useful when we want to ensure that user inputs or string data are strictly numeric without any special characters or spaces.

Python
a = "12345" print(a.isdecimal())  # This will print True as all characters are digits  b = "12345a" print(b.isdecimal())  # This will print False because 'a' is not a decimal character 

Output
True False 

Table of Content

  • Syntax of isdecimal()
  • Example 1: Decimal Point Characters
  • Example 2: Strings with Spaces or Symbols
  • Example 3: Non-Decimal Numeric Characters
  • Example 4: Negative Numbers or Symbols

Syntax of isdecimal()

string.isdecimal()

Parameters

  • The isdecimal() method does not take any parameters. It is simply called on a string object.

Return Type

The method returns:

  • True if all characters in the string are decimal characters (i.e., digits 0-9).
  • False if any character is not a decimal character (including symbols, spaces, letters, etc.) or if the string is empty.

Example 1: Decimal Point Characters

A string that contains a decimal point or any other non-digit characters will return False. For example, strings like “123.45” or “100,000” will fail the check because the period (.) and the comma (,) are not considered decimal digits.

Python
e = "123.45" print(e.isdecimal())  # False, because '.' is not a decimal character  f = "100,000" print(f.isdecimal())  # False, because ',' is not a decimal character 

Output
False False 

Example 2: Strings with Spaces or Symbols

The isdecimal() method does not consider spaces or symbols as decimal characters. Let’s see an example:

Python
d = "12 34" print(d.isdecimal())   # This will print False because there’s a space between the numbers 

Output
False 

Example 3: Non-Decimal Numeric Characters

There are certain numeric characters from other writing systems or formats that look like digits but are not considered decimal digits in Python. For example, the Arabic-Indic numerals or other scripts that represent numbers differently.

Python
c = "١٢٣٤٥"  # Arabic-Indic numerals print(c.isdecimal())  # True, because these characters are considered decimal in their script 

Output
True 
  • However, if the characters belong to a different set, like Roman numerals or fractions, the method will return False.
Python
d = "Ⅻ"  # Roman numeral for 12 print(d.isdecimal())  # False, Roman numerals are not decimal 

Output
False 

Example 4: Negative Numbers or Symbols

The isdecimal() method also returns False when the string contains negative signs (-) or other symbols like currency symbols ($, €, etc.). The presence of any non-decimal character will cause the method to return False.

Python
g = "-12345" print(g.isdecimal())  # False, because of the negative sign  h = "$12345" print(h.isdecimal())  # False, because of the '$' symbol 

Output
False False 



Next Article
Python String isdigit() Method

S

Striver
Improve
Article Tags :
  • Python
  • python-string
Practice Tags :
  • python

Similar Reads

  • String capitalize() Method in Python
    The capitalize() method in Python is used to change the first letter of a string to uppercase and make all other letters lowercase. It is especially useful when we want to ensure that text follows title-like capitalization, where only the first letter is capitalized. Let's start with a simple exampl
    2 min read
  • Python String casefold() Method
    Python String casefold() method is used to convert string to lowercase. It is similar to the Python lower() string method, but the case removes all the case distinctions present in a string. Python String casefold() Method Syntax Syntax: string.casefold() Parameters: The casefold() method doesn't ta
    1 min read
  • Python String center() Method
    center() method in Python is a simple and efficient way to center-align strings within a given width. By default, it uses spaces to fill the extra space but can also be customized to use any character we want. Example: [GFGTABS] Python s1 = "hello" s2 = s1.center(20) print(s2) [/GFGTABS]Ou
    2 min read
  • Python String count() Method
    The count() method in Python returns the number of times a specified substring appears in a string. It is commonly used in string analysis to quickly check how often certain characters or words appear. Let's start with a simple example of using count(). [GFGTABS] Python s = "hello world" r
    2 min read
  • Python - Strings encode() method
    String encode() method in Python is used to convert a string into bytes using a specified encoding format. This method is beneficial when working with data that needs to be stored or transmitted in a specific encoding format, such as UTF-8, ASCII, or others. Let's start with a simple example to unde
    3 min read
  • Python String endswith() Method
    The endswith() method is a tool in Python for checking if a string ends with a particular substring. It can handle simple checks, multiple possible endings and specific ranges within the string. This method helps us make our code cleaner and more efficient, whether we're checking for file extensions
    3 min read
  • expandtabs() method in Python
    expandtabs() method in Python is used to replace all tab characters (\t) in a string with spaces. This method allows for customizable spacing, as we can specify the number of spaces for each tab. It is especially useful when formatting text for better readability or alignment. Let's understand with
    3 min read
  • Python String find() Method
    find() method in Python returns the index of the first occurrence of a substring within a given string. If the substring is not found, it returns -1. This method is case-sensitive, which means "abc" is treated differently from "ABC". Example: [GFGTABS] Python s = "Welcome to GeekforGeeks!"
    2 min read
  • Python String format() Method
    format() method in Python is a tool used to create formatted strings. By embedding variables or values into placeholders within a template string, we can construct dynamic, well-organized output. It replaces the outdated % formatting method, making string interpolation more readable and efficient. E
    9 min read
  • Python String format_map() Method
    Python String format_map() method is an inbuilt function in Python, which is used to return a dictionary key's value. Syntax: string.format_map(z) Parameters: Here z is a variable in which the input dictionary is stored and string is the key of the input dictionary. input_dict: Takes a single parame
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences