Write a function to check whether a given input is an integer or a string.
Definition of an integer :
Every element should be a valid digit, i.e '0-9'.
Definition of a string :
Any one element should be an invalid digit, i.e any symbol other than '0-9'.
Input : 127 Output : Integer Explanation : All digits are in the range '0-9'. Input : 199.7 Output : String Explanation : A dot is present. Input : 122B Output : String Explanation : A alphabet is present.
Below is the implementation of the above idea.
Using special Python built-in type() function:
type() is a built-in function provided by python . type() takes object as parameter and returns its class type as its name says.
Below is the implementation of the above idea:
This article is contributed by Rohit Thapliyal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Check if a given string is a valid number (Integer or Floating Point) | SET 1(Basic approach)
- Check if a given string is a valid number (Integer or Floating Point) in Java
- Check if a given string is a valid number (Integer or Floating Point) in Java | SET 2 (Regular Expression approach)
- Given a string and an integer k, find the kth sub-string when all the sub-strings are sorted according to the given condition
- Rearrange a string in sorted order followed by the integer sum
- Convert a String to Integer Array in C/C++
- Rearrange a string in the form of integer sum followed by the minimized character
- Convert a String to an Integer using Recursion
- Convert string to integer without using any in-built functions
- Program to build DFA that starts and end with 'a' from input (a, b)
- Return maximum occurring character in an input string
- Print all the duplicates in the input string
- Generate two output strings depending upon occurrence of character in input string.
- Generate two output strings depending upon occurrence of character in input string in Python
- Maximum occurring character in an input string | Set-2
- How to input a comma separated string in C++?
- C Program to Check if a Given String is Palindrome
- Python program to check if a string is palindrome or not
- Program to check if first and the last characters of string are equal
- Python program to check if a string contains all unique characters