my_str.isnumeric()
Returns True if all chars in a string are numeric , otherwise rturns False
my_str='abc_45'
print(my_str.isnumeric()) # Output is False
my_str='1234#56'
print(my_str.isnumeric()) # Output is False
my_str='12.34'
print(my_str.isnumeric()) # Output is False
my_str='1234'
print(my_str.isnumeric()) # Output is True
my_str='一千二百三十四'
print(my_str.isnumeric()) # True
print(my_str.isdigit()) # False
print(my_str.isdecimal()) # False
One more example
my_str = '2²'
print(my_str.isnumeric()) # True
print(my_str.isdigit()) # True
print(my_str.isdecimal()) # False
my_str = '½'
print(my_str.isnumeric()) # True
print(my_str.isdigit()) # False
print(my_str.isdecimal()) # False
isdigit() will allow only digits 0-9
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.