Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Doc/tutorial/classes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,13 @@ For example (assuming the above class)::
creates a new *instance* of the class and assigns this object to the local
variable ``x``.

.. note::

Be careful to include the parentheses ``()`` when instantiating.
Writing ``x = MyClass`` (without ``()``) will not create an instance,
and calling ``x.f()`` will raise ``TypeError: missing 1 required positional argument: 'self'``.
The correct usage is ``x = MyClass()``.

The instantiation operation ("calling" a class object) creates an empty object.
Many classes like to create objects with instances customized to a specific
initial state. Therefore a class may define a special method named
Expand Down
Loading