Python

Python Basics #18 — File Read/Write Vol. 2
5 min read

Python Basics #18 — File Read/Write Vol. 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 — File Read/Write Vol. 1
8 min read

Python Basics #17 — File Read/Write Vol. 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.

Python Basics #11 — Sets
4 min read

Python Basics #11 — Sets

Python's set data structure: defining sets, characteristics (unordered, no duplicates, hashable items only), and useful set methods like union, intersection, and difference.

Python Basics #10 — Dictionaries
10 min read

Python Basics #10 — Dictionaries

Learn Python's dictionary data structure: key/value mapping, defining and modifying entries, allowed key types, ordering across Python versions, and the most common dict methods.

Python Basics #8 — Lists
7 min read

Python Basics #8 — Lists

Learn Python's most fundamental data structure: lists. Define, index, slice, iterate, concatenate, and use built-in functions and methods.

Python Basics #7 — Working with Strings
8 min read

Python Basics #7 — Working with Strings

Learn how to work with Python strings: quoting and escaping, concatenation, indexing and slicing, common string methods, and string formatting.

Python Basics #9 — Tuples
7 min read

Python Basics #9 — Tuples

A tuple is very similar to a list, but with key differences. Learn how to define tuples, how they differ from lists, and when to use a tuple instead of a list.