Chapter 4. Making Decisions

So far, you have only seen how to manipulate data directly or through names to which the data is bound. Now that you have the basic understanding of how those data types can be manipulated manually, you can begin to exercise your knowledge of data types and use your data to make decisions.

In this chapter, you learn about how Python makes decisions using True and False and how to make more complex decisions based on whether a condition is True or False.

In this chapter you learn:

  • How to create situations in which you can repeat the same actions using loops that give you the capability to automate stepping through lists, tuples, and dictionaries.

  • How to use lists or tuples with dictionaries cooperatively to explore the contents of a dictionary.

  • How to use exception handling to write your programs to cope with problematic situations that you can handle within the program.

Comparing Values — Are They the Same?

You saw True and False in Chapter 3, but you weren't introduced to how they can be used. True and False are the results of comparing values, asking questions, and performing other actions. However, anything that can be given a value and a name can be compared with the set of comparison operations that return True and False.

Get Beginning Python®: Using Python 2.6 and Python 3.1 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.