Lesson 23: Scope of variables: local and global
Where a variable is created decides where it can be seen. A local variable lives inside its function; a global one lives for the whole program. Mixing them up…
Blog
Long-form pieces and opinion on technology, productivity and teaching.
Where a variable is created decides where it can be seen. A local variable lives inside its function; a global one lives for the whole program. Mixing them up…
A function can be called by position or by name, can have optional arguments, and can accept any number of them. Each style exists to make the call site readable.
A function is a named block of code you can run as often as you like. def creates it, a call runs it, and return sends a value back to whoever called.
A set keeps values with no duplicates and no order. That makes it the fastest way to remove repeats from a list and the natural tool for comparing two groups: what…
A dictionary stores values under named keys instead of numbered positions. That makes it the right structure for records — a student, a product, a config file…
A tuple is an ordered collection that cannot be modified after it is created. That restriction is the point: it is safe to share, cheap to unpack, and the natural…