In the previous chapter, we learned how to create and operate on data structures. Now, let's discuss how to operate on them effectively.
We will first cover loops—a special type of compound statement (code that compounds other code, just like functions)—that allows the same code to be run over and over—any number of times, or even indefinitely. After loops, we will discuss if-else statements—logical forks that allow us to split code execution based on test results. Finally, we will cover two less popular, but still very useful, clauses—try, which helps to save the day if something goes wrong (an error is raised) within the code, and with , which helps to close the context safely (for example, close the file correctly).
Hence, this chapter will cover the following topics:
- Understanding if, else, and elif...