flâneur — a map of the web's best reading

Classes & Iterators - Dive Into Python 3

diveintopython3.net · 3,582 words · saved by 1 readers

Iterators are the “secret sauce” of Python 3. They’re everywhere, underlying everything, always just out of sight. Comprehensions are just a simple form of iterators. Generators are just a simple form of iterators. A function that yields values is a nice, compact way of building an iterator without building an iterator. Let me show you what I mean by that. Remember the Fibonacci generator? Here it is as a built-from-scratch iterator: skip over this code listing Let’s take that one line at a time. class? What’s a class? ⁂ Python is fully object-oriented: you can define your own classes, inherit from your own or built-in classes, and instantiate the classes you’ve defined. Defining a class in Python is simple. As with functions, there is no separate interface definition. Just define the class and start coding. A Python class starts with the reserved word class, followed by the class name. Technically, that’s all that’s required, since a class doesn’t need to inherit from any other class.

Classes & Iterators - Dive Into Python 3 You are here: Home ‣ Dive Into Python 3 ‣ Difficulty level: ♦♦♦♢♢ Classes & Iterators ❝ East is East, and West is West, and never the twain shall meet. ❞ - Rudyard Kipling Diving In Iterators are the “secret sauce” of Python 3. They’re everywhere, underlying everything, always just out of sight. Comprehensions are just a simple form of iterators . Generators are just a simple form of iterators . A function that yield s values is a nice, compact way of building an iterator wit

Explore this link on the map →

related reading