Related Ads Link

Python Isdigit and IsNumeric

Python Isdigit and IsNumeric – Explain String Method

Python isdigit and IsNumeric: Hey hello Everyone this is Rahul from CodingLio. First of all, I would like to thank you for your visits to my post on python string methods. Well, today we are gonna talk about Two of the String Methods i.e Python isdigit and Isnumeric. We will talk about this one by one. If you still have any query, then comment below or Ask that problem in our Programming Community, where professionals will help you. Lets first talk about first string method;

What Does Python isdigit string Method Do?

This method checks whether there are only digits in the given string. If yes then, it prints true otherwise it prints False. This can be helpful for a program many times. you can easily understand this string with the help of a suitable example, here it is;

Example

#!/usr/bin/python

str = “12345”; # Only digit in this string
print str.isdigit()

str = “i just Love CodingLio”;
print str.isdigit()

and here the output is;

True
False

So, what happened in the script above? yes because isdigit founds the Only digit in the first string, As a result it printed True. but in the second String, there were characters with digits, so it just printed False.

What Does Python isnumeric string Method Do?

This string method checks whether any numeric character consists or not. This method is applied to objects with Unicode only. Don’t get me? no need to worry lets head to the Example;

Example

#!/usr/bin/python

str = u”this20044339″;
print str.isnumeric()

str = u”23443444334″;
print str.isnumeric()

And look at the output here;

False
True

Now, It’s clear that you have understood the concept, Here first string consist both numbers and characters false is printed. But in the second string, there are only numeric characters so the True value is printed.

Conclusion:

Today we discussed the Python isdigit and isnumeric string methods with the help of examples. If you really found this helpful don’t forget to share with friends. Hope you enjoyed it Cheers.!!



A Programmer by Passion and a Passionate Blogger by Heart <3 . CodingLio was my Dream Idea, I wanted To Create a Medium where, Geeks can actually Learn Something.


Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: