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



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

1 Answer

+2 votes
by (59.4k 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)