Python for Beginners

Free AI-generated illustrated lesson. Hand-drawn and narrated, step by step.

Python Variables and Types

You've probably been told that variables are boxes that hold your data. But in Python, that common analogy is completely wrong.

In Python, variables are actually just name tags. They are sticky notes clipped onto objects that float around in your computer's memory.

Watch what happens here. If we point x and y to the same list, they both point to the exact same object in memory.

Now for the trap. If we modify y, x changes too, because they both label the exact same thing!

But wait, why doesn't this happen with simple numbers? Let's look at integers.

When you change an integer, Python doesn't modify the number. It creates a brand new number and moves the tag there.

So remember: variables are references, not containers. Master this, and you'll avoid Python's most common bugs.

Lessons in this 9-part set

  • Python Variables and Types
  • Python Lists and Dictionaries
  • Python Loops
  • Python Functions
  • Python Classes
  • File Handling in Python
  • List Comprehensions
  • Error Handling in Python
  • Python vs Java

Watch this free lesson — play it in My Magic Pencil.

▶ Watch free on My Magic Pencil