// resources
Resources
All
|
Cheatsheet
Code Example
Exercise
Template
Other
Achievement
|
Basics
Control Flow
Functions
Data Structures
Modules & Packages
Projects
Object-oriented programming
|
↑ oldest first
↓ newest first
// Code Example
module_time.py
time — sleep, time(), perf_counter. Pause execution, measure elapsed time, and build a countdown. Two functions that co…
// Code Example
module_collections.py
Counter and defaultdict — two tools that eliminate boilerplate. Count occurrences in one line, group items without chec…
// Code Example
module_string.py
Built-in string constants — ascii_letters, digits, punctuation. Check membership, generate passwords, validate input, s…
// Code Example
utils.py
Your first custom module. Three functions, one guard. Place it in the same folder as main.py and import away.
// Code Example
main.py
Imports from utils.py — both patterns side by side. Run this after utils.py is in the same folder.
// Code Example
oop_classes_objects.py
Classes and Objects — blueprint, constructor, self, methods. The foundation of OOP in one file.
// Code Example
oop_attributes_methods.py
Attributes and Methods — instance vs class attributes, default values, methods that read, modify, and return. Everythin…
// Code Example
oop_self.py
Understanding self — what it is, why it exists, how Python passes it automatically, and how it connects data and method…
// Code Example
oop_encapsulation.py
Encapsulation — private attributes, getters, setters, validation inside the object. The object enforces its own rules.
// Code Example
oop_inheritance.py
Inheritance — parent class, child class, super(), method overriding. Write shared logic once, inherit everywhere.
// Code Example
oop_polymorphism.py
Polymorphism — same method call, different behavior per class. One loop, no isinstance() checks, new classes without ch…
// Code Example
oop_special_methods.py
Special Methods — str, repr, len, eq, contains. Make your objects work with print(), len(), ==, and in.