Check if a value is a string

EasyIf-Else Programs · 27 of 64

Write a Python program to check whether the given input is a string.

Advertisement
Input
"sqatools", 100
Output
'sqatools' True
100 False

Approach

  1. Use isinstance(value, str).

Solution

Python
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.

More if-else programs

← All 64 If-Else Programs

Leave a Comment