Skip to content

gh-138011: add note about instantiating MyClass with ( ) #138016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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