Skip to content

Commit 64f3c2e

Browse files
authored
Merge pull request #78 from braboj/codex/add-comment-block-for-type-function
Clarify type example heading
2 parents 590a1b6 + b434c01 commit 64f3c2e

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

examples/08_classes/class_create_with_type.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
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):
3945
x = Robot2("Marvin")
4046
print(x.name)
4147
print(x.func())
42-
print(x.say_hello_b())
48+
print(x.say_hello_b())

0 commit comments

Comments
 (0)