9. Classes — Python 3.9.25 documentation

docs.python.org

Table of Contents | 8. Errors and Exceptions | 10. Brief Tour of the Standard Library | Report a Bug | index | modules | Python | 3.9.25 Documentation | The Python Tutorial

Tin mới

8. Errors and Exceptions

10. Brief Tour of the Standard Library

Python documentation for the current stable release

Python documentation for the current stable release

Classes provide a means of bundling data and functionality together. Creating a new class creates a new type of object, allowing new instances of that type to be made. Each class instance can have attributes attached to

Python Module Index

3.9.25 Documentation

The Python Tutorial

9.2. Python Scopes and Namespaces¶

Before introducing classes, I first have to tell you something about Python’s scope rules. Class definitions play some neat tricks with namespaces, and you need to know how scopes and namespaces work to fully understand

9.2. Python Scopes and Namespaces¶

Before introducing classes, I first have to tell you something about Python’s scope rules. Class definitions play some neat tricks with namespaces, and you need to know how scopes and namespaces work to fully understand

__main__: The environment where the top-level script is run.

Before introducing classes, I first have to tell you something about Python’s scope rules. Class definitions play some neat tricks with namespaces, and you need to know how scopes and namespaces work to fully understand

builtins: The module that provides the built-in namespace.

Before introducing classes, I first have to tell you something about Python’s scope rules. Class definitions play some neat tricks with namespaces, and you need to know how scopes and namespaces work to fully understand

9.3.1. Class Definition Syntax¶

The simplest form of class definition looks like this:

9.3.2. Class Objects¶

Class objects support two kinds of operations: attribute references and instantiation.

9.3.5. Class and Instance Variables¶

Generally speaking, instance variables are for data unique to each instance and class variables are for attributes and methods shared by all instances of the class:

generator.__next__

Generators are a simple and powerful tool for creating iterators. They are written like regular functions but use the yield statement whenever they want to return data. Each time next() is called on it, the generator res

1 1