Chapter Two · The Ground Floor

Values and Names

Every program works with values: numbers, text, and the answers yes and no. This chapter shows what kinds of value Python has, how to give a value a name so you can use it again, where arithmetic surprises people (money especially), how to build text for a person to read, and how to ask the person at the keyboard a question.

The first chapter ended with a program that printed three fixed sentences. That is a start, but a program that always says the same thing is closer to a poster than a tool. To do anything useful, a program has to hold information, work with it, and change it. This chapter builds that ground floor.

Five topics. The four basic kinds of value and how to tell them apart. Names, which let you keep a value and use it later, and a picture of how they work that the rest of the book relies on. Arithmetic, including the one surprise that matters for anyone who handles money. Text, and the modern way to put values into a sentence. And finally input, which lets a program ask a question and use the answer, together with the first crash nearly every beginner meets.

The ground floor of every program
Instructions that use the names
print(f"Total: {price}")
Names that point at values
price, greeting, is_open
Values
42 · 3.5 · "hello" · True

Topics in This Chapter