In this chapter, we’ll take some deep dives into specific Python language subjects. You may have met some of them already. For example, we covered functions in our introduction to Python functions. The advanced Python function concepts in this chapter build on that knowledge.
You don’t have to read these pages in order. Each one stands on its own, so pick the topic you need:
- Python try except: handle errors with try, except, else and finally, raise your own exceptions, and catch several at once with
except*. - Python functions: advanced concepts: forced keyword arguments,
*argsand**kwargs, decorators and anonymous (lambda) functions. - List comprehension: build a new list from another one in a single, readable line, often replacing a whole for loop.
- Python iterator: what happens behind the scenes of a for loop, and how to create your own iterator.
- Python range(): create sequences of numbers with start, stop and step, count backwards, and use range in for loops.
- Python docstring: document your modules, classes and functions in a way that tools and other developers understand.
- Python pass: the statement that does nothing, why Python needs it, and the alternatives.
New to Python? Then start with the introduction to Python chapter first. It covers the basics these pages build on, like variables, loops and functions.