0 votes
1 view
in Python by (107k points)

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

isinstance(x,int);

for integer values?

1 Answer

0 votes
by (47.8k 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')

Or:

var2 = 'this is variable'

if type(var2) == str: 

    print('your variable is a string')

else:

 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
+1 vote
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...