I don\'t know how to check if a variable is primitive. In Java it\'s like this:
if var.isPrimitive():
As every one says, there is no primitive types in python. But I believe, this is what you want.
def isPrimitive(obj):
return not hasattr(obj, '__dict__')
isPrimitive(1) => True
isPrimitive("sample") => True
isPrimitive(213.1311) => True
isPrimitive({}) => True
isPrimitive([]) => True
isPrimitive(()) => True
class P:
pass
isPrimitive(P) => False
isPrimitive(P()) => False
def func():
pass
isPrimitive(func) => False