Skip to content
IT Vizag
← Python Basics

▶ Sign up free for the video, slides & prompts

The lesson below is open to all. Enter your email once to unlock every video, slide deck, prompt and code example on this device.

Checking…

Variables

Lesson 4 of 10 · 1 min read

Give values names so you can store and reuse them.

🎬 Video version coming soon — read it now

A variable is a name that holds a value, like a labelled box. You put something in once and use the name everywhere after.

Creating a variable

🔒 Code example: sign up free (above) to unlock it.

The = sign means "store this value in this name". It is not "equals" like in maths.

Variables can change

🔒 Code example: sign up free (above) to unlock it.

score = score + 5 reads as: take the current score, add 5, and store the result back in score. The short way to write it is score += 5.

Rules for names

  • Letters, numbers and underscores only: total_marks, student2
  • Can't start with a number: 2nd_place is not allowed
  • No spaces: use first_name, not first name
  • Case-sensitive: Age and age are different variables

Good names make good code

🔒 Code example: sign up free (above) to unlock it.

Both work, but six months later only the second one makes sense. Python programmers use snake_case: lowercase words joined with underscores.

Tip: If you can't think of a good name for a variable, you may not yet be sure what it's for. Pause and decide.

In one line

A variable stores a value under a name; = means "store", and good names make code easy to read.

Saved on this device. Sign in to keep progress everywhere.

Share with a friend