In this article, you will see how to check a string is decimal in Python. A decimal string is a string that contains only digits 0-9.
Step 1: Import the necessary module
import string
Step 2: Create a string
str = "1234567890" print("str = ", str) print("str type = ", type(str))
Step 3: Check if the string is decimal
if all(c in string.digits for c in str): print("Decimal") else: print("Not Decimal")
Output:
str = 1234567890
str type = <class 'str'>
Decimal
Free resources to learn advanced skills: AiHints and CodeAllow