Python Tutorials - Herong's Tutorial Examples
∟Classes and Instances
This chapter provides introductions and tutorial examples about classes and instances. Topics include introduction of class, instance, attribute and method; using 'class' statement; using __init__() method; differences between class attributes and instance attributes.
These sections are omitted from this Web preview version. To view the full content,
see information on how to obtain the full version this book.
What Is Class
What Is Class Attribute
What Is Class Method
What Is Class Instance
What Is Instance Attribute
Class Attribute vs. Instance Attribute
What Is __init__() Method
What Is Instance Method
Takeaways:
- A class is an object of the "type" data type that can store data with executable code,
and can instantiate new objects.
- A class attribute is a variable hiding inside a class,
accessible with the attribute reference expression (class.identifier).
- A class method is a function hiding inside a class,
callable with the attribute reference expression (class.identifier(...))
- A class instance is an object instantiated from a given class
using a function call expression, class(...).
- An instance attribute is a variable hiding inside an instance,
accessible with the attribute reference expression (instance.identifier).
- You can access a class attribute using the instance attribute reference expression
(instance.identifier).
- But there is no way to update a class attribute
using the instance attribute reference expression (instance.identifier).
- You can call a class method using the instance method call form
(instance.identifier(...)), which inserts the instance reference into
the argument list as the first argument.
Table of Contents
About This Book
Running Python Code Online
Python on macOS Computers
Python on Linux Computers
Built-in Data Types
Variables, Operations and Expressions
Statements - Execution Units
Function Statement and Function Call
Iterators, Generators and List Comprehensions
►Classes and Instances
Modules and Module Files
Packages and Package Directories
"sys" and "os" Modules
"pathlib" - Object-Oriented Filesystem Paths
"pip" - Package Installer for Python
SciPy.org - Python Libraries for Science
pandas - Data Analysis and Manipulation
Anaconda - Python Environment Manager
Jupyter Notebook and JupyterLab
References
Full Version in PDF/EPUB