Rashina nilofar Rashina
3 months ago
Rashinacountry asked

How can I write a Python program to check whether a value is a string or not?

Sarthak Baral
Expert
last month
Sarthak Baral answered

Hi Rashina,

In Python, you can check this using isinstance():

value = "Hello"

if isinstance(value, str):
    print("It is a string")
else:
    print("It is not a string")

Just replace value with the variable you want to test.

If you have more questions, I am here to help 😊

Python
This question was asked as part of the Number Guessing Game course.