Values Represent the World

A map of the earth, but the continents are drawn with 1s and 0s.

Programming is all about inputting data so that we can manipulate it to get some output. Therefore, we use values to represent the real world as data in the computer.

Values

Three images are shown. Each image is a picture with an arrow pointing to a data representation of the concept. The first picture is a thermometer pointing to the number 23.4 (representing the current temperature). The second picture is an old woman pointing to the number 74 (representing her age). The third picture is a book pointing to the introductory text from a book.

Values can represent anything in the real world that we can measure and concretely describe. Distances, temperatures, peoples’ ages, our names, even the text of entire books.

Writing Values

74
23.4
"Hello world"

When we write values directly in code, we call them “literal values,” as opposed to being received as input from a user. The values are literally written in the code. Sometimes, we also call this “hard coding a value.” Hard-coded values are useful for developing simple programs. However, they are not very exciting on their own. Try running the code shown. What do you notice in the console? Since we have not told Python to print anything, and we have not requested any kind of user input, nothing will appear in the console.

Printing Values

print(74)
print(23.4)
print("Hello world")

Once we have put data into the computer as values, we need to do something with those values. A very simple action is to print the values. Soon, we will learn more complex actions. Review these examples of how we can write literal values and then print them using your REPL editor on the right side of the screen.

Abstraction

When computer scientists use data to represent reality, they are removing extraneous details. When we use the value 74 to represent someone’s age, we are not including any information about how they lived those 74 years. If we describe the current temperature as 23.4, the computer does not understand whether that is hot or cold. This process of reducing detail to make the information easier to fit inside a computer is called abstraction. Although that word might sound a little complicated, the definition is quite simple.

In your literature class, when you summarize a novel for a book review or essay, you are using abstraction. In programming, abstraction is the process of representing information about the real world inside of a computer by choosing to ignore unnecessary details. The details that will be necessary or unnecessary are relative to whatever problem the program is meant to solve. To determine how old someone will be next year, we only need to know how old they are — not how they celebrated their birthday last year or how many times they have been to Canada. By abstracting away those other details, it is easy to represent someone’s age in the computer.

Understanding Values

Picture of a person holding up the number 17 on a piece of paper, with multiple thought bubbles offering conflicting views on what the data represents.

It is very easy to put literal values into a program. However, it is very difficult to immediately understand what those values mean. It is up to us programmers to communicate the meaning of values. The value 17 could be used to represent the age of a person, the age of a dog, the amount of money in a wallet, or the number of times they have traveled to Canada. We will learn more ways to write programs so that it is easier to understand what a value represents. For now, though, it is important to understand that values on their own have no meaning.

Summary