Data Type Fundamentals
The Python programming language uses data types to distinguish between different types of information.
Dependencies
Students need to have these skills before learning this skill:
Goal
When you teach this skill, your goal is to make it so that students know the following:
- Every value has a data type.
- The
intdata type is used for storing whole numbers. - The
strdata type is used for storing text.
Activities
Here are some activities that you can do in order to teach this skill.
Two different kinds of addition
-
Explain that every value in the Python programming language has a data type.
-
Write
100on the board. Explain that100is anint. Explain that we store whole numbers inints. -
Write
"Hello!"on the board. Explain that"Hello!"is a string. Explain that we store text in strings. -
Ask students to come up with two examples of
ints. For this example, let’s say that students came up with these twoints:101and102. -
Write an addition expression on the board that uses the two
ints. In this example, you would write101 + 102. -
Ask the students what the result of that expression is going to be.
-
Now, ask students tog come up with two examples of strings. For this example, let’s say that students came up with these two strings:
"hot"and"dog". -
Write an addition expression on the board that uses the two strings. In this example, you would write
"hot" + "dog". -
Ask the students what the result of that expression is going to be.
-
Now, write this code on the board:
p1_score = 7 -
Ask students to tell you what the data type for the
p1_scorevariable is. -
Add some more code to what you wrote on the board. At this point, the entire program that’s written on the board should look like this:
p1_score = 7
p2_score = 11 -
Ask students to tell you what the data type for the
p2_scorevariable is. -
Add some more code to what you wrote on the board. At this point, the entire program that’s written on the board should look like this:
p1_score = 7
p2_score = 11
print("Total score:")
print(p1_score + p2_score) -
Ask students what they think the program is going to do, and then explain what it actually does.
-
Add some more code to what you wrote on the board. At this point, the entire program that’s written on the board should look like this:
p1_score = 7
p2_score = 11
print("Total score:")
print(p1_score + p2_score)
p1_name = "Alice"
p2_name = "Bob"
print("Good work, " + p1_name + " and " + p2_name + "!") -
Ask students what they think the program is going to do, and then explain what it actually does.
-
Add some more code to what you wrote on the board. At this point, the entire program that’s written on the board should look like this:
p1_score = 7
p2_score = 11
print("Total score:")
print(p1_score + p2_score)
p1_name = "Alice"
p2_name = "Bob"
print("Good work, " + p1_name + " and " + p2_name + "!")
print(p1_score + p1_name) -
Ask students what they think the program is going to do, and then explain what it actually does.