Python Practice › If-Else Programs › Program 27
Check if a value is a string
Write a Python program to check whether the given input is a string.
Input
"sqatools", 100
Output
'sqatools' True 100 False
Approach
- Use
isinstance(value, str).
Solution
for value in ["sqatools", 100]: print(repr(value), isinstance(value, str))Output
'sqatools' True 100 False
Line by line
Line 2
isinstance returns the True/False answer directly.
Learn the concept
New to this topic? Read the lesson, then come back.