Summary

In this chapter we saw how to branch using if, and how to create multiway branches using if with elifs and, optionally, with else. We also saw how to loop using while and for, and how to generate lists of integers using range(). We learned about the dictionary methods that provide a dictionary's keys, values, and key-value pairs (items), and we took a brief look at sorting. We also had a glimpse at how to use Python's list comprehensions and generators.

We saw how to create functions using def (and with lambda). We used positional and keyword arguments, and we developed two useful functions, frange() and simplify(). We saw how Python creates functions dynamically as it reads a .py file, and how we can use this dynamism to provide similar functionality in older Python versions to that which is available in newer versions. And we saw how to use partial function application to create wrapper functions that encapsulate a function with its arguments (closures).

We also learned how to raise exceptions, how to create custom exceptions, and how to handle exceptions. We saw how to use finally to guarantee cleanup, and we discussed some of the more complex exception-handling possibilities that Python offers. We also saw that exception handling can lead to cleaner code when we have suites where multiple exceptions could occur, and how they can be used to cleanly exit a set of deeply nested loops.

Creating custom exceptions led us on to creating simple classes; classes that have no attributes (no member data) and no methods. In the next chapter we will look more formally at classes, and learn how to create them and instantiate instances of them, with any attributes and methods we wish.

Was this article helpful?

0 0
Tube Jacker

Tube Jacker

Download Tube Jacker And Discover Everything You Need To Know About Jacking Unlimited Traffic From The Video Giant. The drop dead easy way to create winning video campaigns that will FLOOD your website with unstoppable FREE traffic, all on complete and total autopilot. How to exploit a sneaky method of boosting exposure and getting your videos to the top of Google within 72 hours, guaranteed.

Get My Free Ebook


Post a comment