Classes in Python are also objects that create an object whenever the Class,python interpreter is executed using the keyword.
Class Test (object):
Pass
Test = Test ()
Print (test)
Determines whether an object is---> in a class
Hasattr (OBJ,STR)
Class Test (object):
Pass
Test = Test ()
Print (test)
Print (test)
def info (o):
Print (o)
You can pass a class as a parameter to a function
Info (test)
You can add a new property to a class:
Class Test (object):
Pass
Test = Test ()
Print (test)
Print (Test)
def info (o):
Print (o)
Info (test)
Print (Hasattr (Test, ' new attribute '))
Test.new_attribute = ' haha '
Print (Hasattr (Test, ' New_attribute '))
Print (Test.new_attribute)
Operation Result:
<__main__. Test Object at 0x00000198f952c198>
<class ' __main__. Test ' >
<__main__. Test Object at 0x00000198f952c198>
False
True
haha
Note: Determine whether an object is in a class, using HASATTR, Format hasattr (OBJ,STR)
13. 02python Language Fundamentals (dynamically created classes)
Dynamically creating classes
def choose_name (name):
If name = = ' Haha '
class Haha (object):
Pass
return haha
else:
Class Heihei (object):
Pass
Return Heihei
My_class = choose_name (' haha ')
Print (My_class)
Print (My_class ())
13.01python Language Foundation (META Class)