By @alesanchezr and other contributors at 4Geeks Academy
Estas instrucciones también están disponibles en Español 🇪🇸
Learn to model problems with objects: create classes with attributes and methods, customize how objects are printed and compared, reuse code with inheritance, protect data with properties, combine objects with composition and build your own iterators.
This LearnPack is part of a series. We recommend completing them in order:
| # | LearnPack | What you practice |
|---|---|---|
| 1 | Python for Beginners | print, variables, input and basic operations |
| 2 | Python Functions | defining and calling functions, parameters and return |
| 3 | Python Lists and Loops | lists, for/while loops and iteration patterns |
| 4 | Master Python: Functions and Numbers | functions, arithmetic operators, the math module, conditionals and simple loops |
| 5 | Master Python: Strings and Collections | strings, lists, tuples, dictionaries, sets, comprehensions and sorting |
| 6 | Master Python: Classes and OOP (📍 you are here) | classes, special methods, inheritance, properties, composition, dataclasses and iterators |
⬅️ Previous: Master Python: Strings and Collections
🏁 This is the last LearnPack of the path.
Open in Codespaces.
Once VS Code is open, LearnPack should start automatically. If it doesn't, run
learnpack startin the terminal.
-
Install LearnPack, the Python plugin and the testing tools:
npm i @learnpack/learnpack -g && learnpack plugins:install @learnpack/python
pip3 install pytest==6.2.5 pytest-testdox mock- Clone this repository and start the exercises:
git clone https://github.com/4GeeksAcademy/master-python-classes-exercises.git
cd master-python-classes-exercises
learnpack start- Exercises:
001-017 - Focus: classes and instances,
__init__,__str__,__repr__,__eq__, class attributes, inheritance andsuper(), polymorphism,@staticmethod,@classmethod,@property, composition, abstract classes,@dataclass, generators and iterators - Difficulty: intermediate
Each exercise folder contains:
README.md/README.es.md: the instructions (English / Spanish).app.py: the starter file where you write your solution.test.py: the automatic grading tests. You don't need to open it, but you can read it if you are stuck.
Click Run to execute your app.py and Test to grade it.
These exercises were originally part of Master Python. Thanks to Alejandro Sánchez (alesanchezr), Paolo (plucodev), Marco Gómez (marcogonzalo) and every contributor. Found a typo or a bug? Open an issue.