compare types in python 1

compare types in python

obj = "str"

isinstance(obj, str) # will return True
isinstance(obj, int) # will return False

Here is what the above code is Doing:
1. We create a variable called obj and assign it the value of “str”
2. We then use the isinstance() function to check if obj is an instance of the str class.
3. We then use the isinstance() function to check if obj is an instance of the int class.

Similar Posts