4 Reading Python code: Part 1
This chapter covers
- Why knowing how to read code is important
- How to ask Copilot to explain code
- Using functions to break down large problems
- Using variables to hang on to values
- Using if-statements to make decisions
- Using strings to store and manipulate text
- Using lists to collect and manipulate many values
In chapter 3, we used Copilot to write several functions for us. What are they good for? Maybe our money_made
function could be part of a stock trading system, our is_strong_password
function could be used as part of a social networking website, or our best_word
function could be used as part of some Scrabble AI. Overall, we’ve written some useful functions that could be part of larger programs. And, we did this without writing much code ourselves or, indeed, understanding what the code even does.
However, we believe that you need to understand at a high level what code does. Because this will require some time to learn, we’ve split this discussion over two chapters. In this chapter, we’ll explain why reading code is important and introduce you to a Copilot feature that can help you understand the code. After that, we’ll dive into the top 10 programming features you’ll need to recognize to read most basic code produced by Copilot. We’ll do the first five in this chapter and the remaining five in the next chapter. Don’t worry: you’ve actually been informally introduced to all 10 already—we’re just going to deepen your understanding of each one.