xxxxxxxxxx
# To check types use the type() function
my_type = ["anyting","a string",55,5.5]
checking_type = type(my_type)
print(checking_type)
xxxxxxxxxx
# To check the type of a variable
print( type(price) )
# To check if a veriable is an instance of something (float in this case)
print( isinstance(price, float) )
xxxxxxxxxx
# To check if the type of o is exactly str, excluding subclasses of str:
if type(o) is str:
# Use isinstance to check if o is an instance of str or any subclass of str:
if isinstance(o, str):
xxxxxxxxxx
# Example variables
var1 = "Hello"
var2 = 123
var3 = True
var4 = 3.14
# Check type of variables
print(type(var1)) # <class 'str'>
print(type(var2)) # <class 'int'>
print(type(var3)) # <class 'bool'>
print(type(var4)) # <class 'float'>