#Python

147 posts

Python — OOP Part 2: Class and Instance
4 min read

Python — OOP Part 2: Class and Instance

Class and instance — what objects really are in Python, how to define a class with __init__, and the role of `self` in instance methods.

Python — OOP Part 1: What Is Object-Oriented Programming, and Why Use It?
8 min read

Python — OOP Part 1: What Is Object-Oriented Programming, and Why Use It?

An introduction to Object-Oriented Programming (OOP) — what it is, when to use it, and how it cleans up duplicated data and behavior compared to dictionaries and lists.

Python Basics #20 — Modules and Packages Vol. 2
4 min read

Python Basics #20 — Modules and Packages Vol. 2

Continuing from the previous lesson on modules, this post covers packages: how to organize modules into folders, sub-packages, the role of __init__.py, and convenient imports for users.

Python Basics #20 — Modules and Packages Vol. 1
6 min read

Python Basics #20 — Modules and Packages Vol. 1

Modules and packages aren't hard. This lesson explains what modules are, why we use them, how Python resolves imports, and how to create and import your own modules.

Python Basics #19 — Errors and Exception Handling
7 min read

Python Basics #19 — Errors and Exception Handling

Handle errors gracefully with try/except/else/finally. Catch specific built-in exceptions, fall back to a base Exception, and understand why the order of except clauses matters.

Python Basics #18 — Reading and Writing Files, Part 2
5 min read

Python Basics #18 — Reading and Writing Files, Part 2

Continuing from the previous lesson, this post covers writing files in Python — w/x/a modes, write vs print, persisting and reloading list/dict data, and append-mode caveats.

Python Basics #17 — Reading and Writing Files, Part 1
8 min read

Python Basics #17 — Reading and Writing Files, Part 1

Read and write text files in Python: the open function, file modes, the cursor model, read vs readlines vs iterating the file object, and a memory/performance comparison.

Python Basics #16 — Functions
3 min read

Python Basics #16 — Functions

Learn Python functions: defining and calling, parameters and arguments, default values, returning values, namespaces, and refactoring repeated code into reusable functions (D.R.Y.).

Python Basics #15 — for Loop
7 min read

Python Basics #15 — for Loop

Python's for loop is used to iterate over a collection of data. It's similar to while in many cases but more convenient, so it's the more commonly used loop.

Python Basics #14 — while Loop
3 min read

Python Basics #14 — while Loop

Python provides two loop statements: while and for. The while loop has a test block and a body — it evaluates the test, runs the body if True, and repeats until the test becomes False.

Python Basics #13 — if Statement
6 min read

Python Basics #13 — if Statement

An if statement has if, elif, and else blocks. Each block has a test expression and a body that runs when the test passes. If the test is True the body runs; if False the next elif is tested; if all tests are False the else body runs.

Python Basics #12 — Control Flow & Operators
8 min read

Python Basics #12 — Control Flow & Operators

Just like people make decisions based on conditions, programs need to choose what to run based on conditions. Control-flow statements drive that, and operators feed the conditions. This lesson covers the concepts and walks through arithmetic, assignment, comparison, logical, identity, and membership operators.