Python
Generators, the GIL, defaults and the interpreter underneath.
The course
Open the courseStart at 01. The first lesson names the types. The next one builds an object. Each sample is on the page.
-
Skill
Basics
The types, explained, then an object you can name and call.
-
01
Python from zero: a value has a type
Start here
Every Python value has a type. name is a str, cents is an int, and ready is a bool. The program prints latte $4.50 ready, then str int bool.
Adds The types this course uses
-
02
Python from zero: a class is the object
A class groups fields and a method. Item stores a drink and a price in cents. label prints latte $4.50.
Adds An object you can name and call
-
01
Python from zero: a value has a type
Start here
-
Practice
Tips
A rule that prevents a bug, then a program that uses the object.
-
03
Python from zero: two names can share one list
Assigning a list to a second name does not copy it. list() does. The program adds a muffin to the ticket and prints ['latte'] ['latte', 'muffin'].
Adds A tip that prevents a bug
-
04
Python from zero: a method uses self
A method changes the object through self. A bill starts at 0 cents, add puts a latte on it, and the program prints 450.
Adds A program that uses the object
-
03
Python from zero: two names can share one list
-
Further
A whole program
One more idea, then a program that puts the pieces together.
-
05
Python from zero: money is a Decimal
A price is a Decimal made from a string, not a float. Three americanos at 4.10 print 12.30, and the total equals Decimal("12.30").
Adds A program that puts the pieces together
-
06
Python from zero: a method is enough
A function can call label on any object that has label. Item has that method. show prints latte $4.50.
Adds A program that puts the pieces together
-
05
Python from zero: money is a Decimal
GoByte Skills: Python track, 3 lessons. Generators, the GIL and default arguments: what Python actually does when your code runs.
Open the Python trackArticles
RSS-
Mutable defaults: evaluated once
GoByte Skills #9: A default argument is evaluated when def runs, not on each call, and stored on the function. So a list default is one list that every call shares. Why, the None fix, and why += is the same bug in disguise.
-
The GIL: threads for waiting, processes for work
GoByte Skills #8: The GIL lets one thread run Python bytecode at a time. Four threads on CPU work finish no faster than one. Four processes really run in parallel. Measured, plus why the __main__ guard is not style.
-
Generators: a function you can pause
GoByte Skills #7: Calling a generator function runs none of its body. Each next() resumes a frozen frame up to the next yield, so a billion values cost one frame of memory. Plus the one pass trap that fails silently.