Python: Check whether variable is integer or string
Python Basic: Exercise-144 with Solution
Write a Python program to check whether a variable is integer or string.
Sample Solution :-
Python Code :
print(isinstance(25,int) or isinstance(25,str)) print(isinstance(,int) or isinstance(,str)) print(isinstance("25",int) or isinstance("25",str))
True False True
Visualize Python code execution:
The following tool visualize what the computer is doing step-by-step as it executes the said program:
Python Code Editor :
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to determine whether the python shell is executing in 32bit or 64bit mode on operating system.
Next: Write a Python program to test whether a variable is a list or tuple or a set.
What is the difficulty level of this exercise?
Test your Python skills with w3resource's quiz
Python: Tips of the Day
Unpack variables from iterable:
# One can unpack all iterables (tuples, list etc) >>> a, b, c = 1, 2, 3 >>> a, b, c (1, 2, 3) >>> a, b, c = [1, 2, 3] >>> a, b, c (1, 2, 3)
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework