How to check if a variable is string or not in Python

2 Answers

0 votes
s = "Python programming language"

if type(s) == str:
    print("True")
else:
    print("False")


     
     
'''
run:
     
True

'''

 



answered Apr 12, 2021 by avibootz
0 votes
s = "Python programming language"

if isinstance(s, str):
    print("True")
else:
    print("False")


     
     
'''
run:
     
True

'''

 



answered Apr 12, 2021 by avibootz
...