Unit 1 · Lesson 2

Values, Types & Expressions

Discover what Python data means and what it can do.

🎮 Gaming Data Everywhere

A game stores different kinds of information for different jobs.

🕹️ Discover the Data

Reveal each stat and decide what kind of value it needs.

Level
15

Can you be Level 15.5? Why must this be a whole number?

Crit Multi
1.5x

Wait, 1x damage is normal, but 2x is too much. How do we store that precise 1.5x boost?

Is Alive
True

Only "Yes" or "No". Do we need a number for this status?

🏷️ Four Python Types

A type describes what kind of value Python is working with.

int

Whole numbers such as 8, 0, and -12.

float

Numbers with a decimal point, such as 3.5.

str

Text enclosed in matching quotes.

bool

Exactly True or False, with capital letters.

🔎 Same Look, Different Type

Punctuation changes how Python understands a value.

3

int

A whole-number value.

3.0

float

A decimal-number value.

"3"

str

A one-character text value.

True / "True"

bool or str?

True is a boolean. Quotes turn "True" into text.

🔍 Type Check (1/4)

Name the type of this value before revealing the answer.

type_check.py

🔍 Type Check (2/4)

Name the type of this value before revealing the answer.

type_check.py

🔍 Type Check (3/4)

Name the type of this value before revealing the answer.

type_check.py

🔍 Type Check (4/4)

Name the type of this value before revealing the answer.

type_check.py

📦 Values Written in Code

A literal is written directly; an expression is evaluated to produce a value.

42

Literal

42 is written directly, so Python can use that value immediately.

3 + 4

Expression

Python evaluates 3 + 4 to produce the value 7.

⚙️ Expressions Produce Values

Python evaluates each expression before print() displays its result.

expressions.py
Console Output
7 4.7 Python True

🔍 Value and Type (1/3)

Write both the result and its type.

expression_check.py

🔍 Value and Type (2/3)

Write both the result and its type.

expression_check.py

🔍 Value and Type (3/3)

Write both the result and its type.

expression_check.py

➕ One Symbol, Two Behaviors

The types on both sides determine what + does.

3 + 4

Numeric Addition

Two numbers combine mathematically to produce 7.

"3" + "4"

String Concatenation

Two strings join in order to produce "34".

🔍 Addition or Concatenation?

Predict the exact output. Use the quotes as evidence.

plus_check.py

🔬 Meet type()

type() reports the kind of value Python sees.

type(3.5)

A Type Detective

Use type() after making a prediction, then compare the evidence with your idea.

✅ Check with type()

The displayed class name confirms each value's type.

type_check.py
Console Output
8 <class 'int'> <class 'float'> <class 'str'> <class 'bool'>

🔍 Mixed Types

What happens when Python runs this line?

mixed_types.py

📝 Homework

Complete it on time and submit it before the deadline.

🔖 Summary

Key takeaways from this lesson.

Values

Literals and expressions produce values.

Types

int, float, str, and bool describe different kinds of values.

Test

Predict first, then run and use type() to verify.

🏷️ Task 1: Classify the Values

Write int, float, str, or bool beside each value.

Your Goal

1. Classify all twelve values as int, float, str, or bool.

Values
8     8.0     "8"     True
-3    0.25    "False" False
0     -2.5    "3.0"   "Python"

🔮 Task 2: Predict Value and Type

Predict first, then run each expression to check.

Your Goal

1. Write the resulting value and type for every line.

2. Run the code and correct any prediction that differs.

Example Code

🧱 Task 3: Build Four Examples

Create one clear example of every type.

Your Goal

1. Write four print() calls: one int, one float, one str, and one bool.

2. Make the four displayed values visibly different.

3. Run the program and check the output.

🔬 Task 4: Investigate with type()

Use evidence to compare values that look similar.

Your Goal

1. Predict the type of each supplied value.

2. Use type() to test every prediction.

3. Write one sentence explaining why 5, 5.0, and "5" differ.

Example Code

🛠️ Task 5: Repair the Operation

Decide the intended result before changing the code.

Your Goal

1. Run the broken line and read the error.

2. Repair it once to produce the number 79.

3. Repair it a different way to produce the text 709.

4. Explain how changing the types changed the behavior of +.

Example Code
01 / 26