File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- """
2- type(object)
3- type(name, bases, dict)
4-
5- """
1+ # Using ``type`` to inspect objects and create classes
2+ # -----------------------------------------------------------------------------
3+ # ``type(object)``
4+ # ``type(name, bases, dict)``
5+ #
6+ # The built-in ``type`` function has two distinct behaviors in Python:
7+ # 1. ``type(obj)`` returns the type of ``obj``. This is useful when
8+ # inspecting existing objects to see what class they belong to.
9+ # 2. ``type(name, bases, dict)`` dynamically creates a new class with the
10+ # specified name, base classes and attributes. Using this form allows
11+ # programs to build classes at runtime.
612
713##############################################################################
814# USECASE A : Get object type
@@ -39,4 +45,4 @@ def say_hallo_b(self):
3945x = Robot2 ("Marvin" )
4046print (x .name )
4147print (x .func ())
42- print (x .say_hello_b ())
48+ print (x .say_hello_b ())
You can’t perform that action at this time.
0 commit comments