This directory contains projects focused on understanding and implementing advanced concepts of object-oriented programming (OOP) in Python. The tasks cover topics such as class and instance attributes, class methods, static methods, properties, and more.
- Object Oriented Programming
- Object-Oriented Programming
- Class and Instance Attributes
- classmethods and staticmethods
- Properties vs. Getters and Setters
- str vs repr
- Why Python programming is awesome
- What is OOP
- “first-class everything”
- What is a class
- What is an object and an instance
- What is the difference between a class and an object or instance
- What is an attribute
- What are and how to use public, protected and private attributes
- What is
self
- What is a method
- What is the special
__init__
method and how to use it - What is Data Abstraction, Data Encapsulation, and Information Hiding
- What is a property
- What is the difference between an attribute and a property in Python
- What is the Pythonic way to write getters and setters in Python
- What are the special
__str__
and__repr__
methods and how to use them - What is the difference between
__str__
and__repr__
- What is a class attribute
- What is the difference between an object attribute and a class attribute
- What is a class method
- What is a static method
- How to dynamically create arbitrary new attributes for existing instances of a class
- How to bind attributes to objects and classes
- What is and what does contain
__dict__
of a class and of an instance of a class - How does Python find the attributes of an object or class
- How to use the
getattr
function
Task | File | Description |
---|---|---|
0. Simple rectangle | 0-rectangle.py | Write an empty class Rectangle that defines a rectangle. |
1. Real definition of a rectangle | 1-rectangle.py | Write a class Rectangle that defines a rectangle by its width and height. |
2. Area and Perimeter | 2-rectangle.py | Write a class Rectangle that includes methods to calculate the area and perimeter. |
3. String representation | 3-rectangle.py | Write a class Rectangle that includes a method to return a string representation of the rectangle. |
4. Eval is magic | 4-rectangle.py | Write a class Rectangle that includes a method to return a string representation for reproduction. |
5. Detect instance deletion | 5-rectangle.py | Write a class Rectangle that prints a message when an instance is deleted. |
6. How many instances | 6-rectangle.py | Write a class Rectangle that keeps track of the number of instances created. |
7. Change representation | 7-rectangle.py | Write a class Rectangle that allows changing the string representation character. |
8. Compare rectangles | 8-rectangle.py | Write a class Rectangle that includes a method to compare the area of two rectangles. |
9. A square is a rectangle | 9-rectangle.py | Write a class Rectangle that includes a class method to create a square. |
10. N queens | 101-nqueens.py | Write a Python program that solves the N queens puzzle. |