This repository contains the Python examples I created while learning Python. The files below are arranged in a suggested learning order, from beginner fundamentals to more advanced topics.
Click any lesson title to open its Python file directly.
- Start with Section 1: Getting Started.
- Open each linked file, read the comments, and try to predict its output.
- Run a file with
python3 "filename.py". - Change the examples and run them again.
- Complete the small projects after learning the related concepts.
Note
Some original filenames contain spaces or spelling mistakes. Their display names are corrected below, while the files themselves are unchanged so existing imports continue to work.
- First Python Program — program structure and the
__main__check - Variables — storing strings, numbers, and Boolean values
- Multiple Assignment — assigning several variables at once
- Type Casting — converting between data types
- User Input — reading values from the keyboard
- Math Functions — common operations from the
mathmodule - String Methods — inspecting and changing strings
- String Formatting — formatting text and numbers
- Index Operator — accessing characters by position
- String Slicing — extracting parts of strings
- Nested Function Calls — using one result inside another call
- Logical Operators — using
and,or, andnot - Walrus Operator — assignment expressions with
:=
- If Statements — conditional execution
- While Loops — repeating while a condition is true
- For Loops — iterating a fixed number of times
- Nested Loops — using a loop inside another loop
- Loop Control Statements —
break,continue, andpass
- Lists — ordered, changeable collections
- Two-Dimensional Lists — lists containing other lists
- Tuples — ordered, unchangeable collections
- Sets — unique, unordered values
- Dictionaries — key-value pairs and nested dictionaries
- Sorting —
sort()andsorted() - Zip Function — combining multiple iterables
- List Comprehensions — concise list creation
- Dictionary Comprehensions — concise dictionary creation
- Functions — defining and calling functions
- Return Statements — returning values from functions
- Keyword Arguments — passing arguments by name
*args— accepting a variable number of positional arguments**kwargs— accepting a variable number of keyword arguments- Variable Scope — local, enclosing, global, and built-in scope
- Functions Assigned to Variables — treating functions as objects
- Higher-Order Functions — passing or returning functions
- Lambda Functions — small anonymous functions
map()— transforming iterable itemsfilter()— selecting iterable itemsreduce()— reducing an iterable to one value
- Creating a Module — reusable functions for importing
- Using Modules — different import styles
__name__and__main__— running versus importing a module__name__Companion Example — observing the module name- Random Module — random numbers, choices, and shuffling
- Time Module — timestamps and time formatting
- Defining a Class — a reusable
Carclass - Creating and Using Objects — importing and instantiating the
Carclass - Person Class Example — instance attributes and methods
- Class Variables — class and instance variables
- Using Class Variables — shared values across objects
- Objects as Arguments — passing objects to functions
- Inheritance — parent and child classes
- Multilevel Inheritance — inheritance across several levels
- Multiple Inheritance — inheriting from multiple parents
- Method Overriding — replacing inherited behavior
super()— calling a parent implementation- Method Chaining — calling methods sequentially
- Duck Typing — using behavior instead of strict types
- Abstract Classes — defining required methods with
abc - OOP and SOLID Practice — encapsulation, inheritance, abstraction, polymorphism, duck typing, and composition in one example
- Exception Handling —
try,except,else, andfinally - Detecting Files and Directories — checking paths with
os.path - Reading a File — reading text with a context manager
- Writing a File — writing text with a context manager
- Copying a File — copying with
shutil - Moving a File — moving with
os.replace - Deleting Files and Directories — removing filesystem content
Caution
Review the paths before running the move or delete examples. They can change or remove files. Some path examples were written for Windows and need to be changed before use on Linux.
- Multithreading — running multiple I/O-style tasks concurrently
- Quiz Game — functions, dictionaries, loops, input, and scoring
- Rock Paper Scissors — loops, conditions, input, and randomness
- General Practice — assorted exercises and experiments
The main progression is:
Basics → Strings → Conditions and loops → Collections → Functions → Modules → OOP → Exceptions and files → Multithreading → Projects
Do not worry about memorizing everything. Type the examples yourself, experiment with them, and return to earlier lessons whenever a later topic feels unclear.