When you put a piece of Python data into a “for” loop, the loop doesn’t execute on the data itself. Rather, it executes on the data’s “iterator.” An iterator is an object that knows how to behave inside a loop. Let’s take that apart. First, let’s assume that I say: ...
One of the first things that Python programmers learn is that you can easily read through the contents of an open file by iterating over it: f = open('/etc/passwd') for line in f: print(line) Note that the above code is possible because our file object “f” is an ...
The latest draft of “Practice Makes Python,” my ebook intended to sharpen your Python programming skills, is now out. This draft includes all 50 exercises, solutions, and explanations that I had hoped to include in the book. I’m very excited to have reached this milestone, and appreciate the input from ...
My first ebook, “Practice Makes Python” — containing 50 exercises that will help to sharpen your Python skills — is now available for early-bird purchase! The book is already about 130 pages (and 26,000 words) long, containing about 40 exercises on such subjects as basic data structures, working with files, functional programming, and object-oriented ...
Newcomers to Python are often amazed to discover how easily we can create new classes. For example: class Foo(object): pass is a perfectly valid (if boring) class. We can even create instances of this class: f = Foo() This is a perfectly valid instance of Foo. Indeed, if we ask it ...
It’s time again for me to offer a free Webinar, as well as two online courses: I’m repeating my hour-long free Webinar about functional programming in Python on Wednesday, October 22nd. When I offered it last month, more than 200 people got tickets, and 70 participated. I had a blast, ...