Thursday, July 7, 2022
HomeProgrammingPython Verify if String is Integer

Python Verify if String is Integer


On this article, we’ll write a program in python that can verify if a string is an integer or not.

We are going to create a perform that can take a string as enter and returns a Boolean worth (true or false) based mostly on the situation whether it is an integer or not. We are going to take the enter from the consumer and name the perform. After storing the consequence, we’ll print on the console whether or not the string is an integer or not.

If all of the characters of an inputted string are between ‘0’ and ‘9’, then it signifies that the string is an integer.

For Instance:

123, It’s an Integer as a result of all of the characters are between 0 and 9.

35446554667876832, Additionally it is an Integer as a result of all of the characters are between 0 and 9 solely.

234t5, It isn’t an Integer as a result of it comprises a personality ‘t’ which isn’t between 0 and 9.

If any character will not be following the rule, then we will take into account that the string will not be an Integer.

Testcase 1: When the enter is 123.

Output:

Testcase 2: When the enter is 236r.

Output:

Python Check if String is Integer

If all of the characters of a string are between 0 and 9 then we will say that the string is an integer in any other case it’s not thought-about an integer. We’ve got seen this system for a similar the place we created a perform that takes a string as enter and tells us if the string is an integer or not.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments