Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (106k points)

Is there a way to check if the type of a variable in python is string.. like


for integer values?

1 Answer

0 votes
by (47.6k points)
  • The correct way of solving this problem is:-

isinstance(s, str)

  • You can also solve this problem in the following way:-

if type(x) == str:

  • Another thing you can do is:-

var = 1 

if type(var) == int:

   print('your variable is an integer')


var2 = 'this is variable'

if type(var2) == str: 

    print('your variable is a string')


 print('your variable IS NOT a string')

  • I hope these answers will help you in clearing your doubts regarding this question.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories