+1 vote
in Programming Languages by (72.7k points)
Is there any function that I can use to check the type of a variable in Python?

E.g.

x='hello'

If I check whether or not x is a string, it should return True.

1 Answer

+2 votes
by (77.2k points)
selected by
 
Best answer

You can check if a variable is of a certain type in Python using the "isinstance()" function. 

Here is an example to check if x is a string:

>>> x='hello'

>>> isinstance(x, str)

True


...