Tutorial 2/15 The Basics

Python: Variables

Learn how to store, name, and modify data in labeled containers.

The Hook

Think of a Variable like a labeled storage box.

  • The Label is the variable name (e.g., score).
  • The Content is what's inside (e.g., 100).

You can change what's inside the box at any time, but the label stays the same!

Score
999

Assignment Logic

Read the comments to see how we fill the containers correctly.

username = "Ninja"
# Create box 'username'
score = 500
# Set score to 500
print(score)
# Show what's in 'score'

Power Up: Arithmetic

The Regulars

10 + 5 15
10 / 3 3.33
10 * 2 20

Techniques

% Remainder (Modulo)
// Integer Division
** Power of (Exponent)
Logic Hub

Predict

What happens when we overwrite a variable?

lives = 3
lives = 0
print(lives)

Live Python Lab

Assignments and Variables.

> SYSTEM READY_
> _
BRONZE

🥉 New High Score

Change the score from 100 to 999.

> _
SILVER

🥈 Correct the Assignment

Values must go on the RIGHT. Fix the backwards code!

> _
GOLD

🥇 Character Profile

Create hero, level, and lives variables. Then print them.

> _