xxxxxxxxxx
#builtins
isinstance(integer,int)
issubclass(Derived,Base)
type(var)
#pip install danielutils
from danielutils import isoneof,areoneof
isoneof(number,[int,float])
numbers=[ ]
areoneof(numbers,[int,float])
#if you need something more robust for functions use validate decorator ->
from danielutils import validate
#ttps://www.google.com/search?q=python+type+validation
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'>