Skip to content
AgileLogics
4 min read

Variables

Prerequisites: Python syntax

A variable is a named place to store a value so you can use or change it later.

Real-world analogy: a variable is like a labeled box — write a label on it, put something inside, and read or replace the contents later by referring to the label.

Syntax

name = "Ada"

Example

age = 25
print(age)
age = 26
print(age)

Expected output

25
26

Python variables need no declared type — age = 25 creates an integer variable simply because 25 is an integer; assigning age = "twenty" later would make it a string instead.

Common mistakes

  • Using a variable before assigning it a value — Python raises NameError: name 'x' is not defined.
  • Variable names are case-sensitive: age and Age are two different variables.

Practice

Create a variable called city holding your city's name, then print it.

Show solution
city = "Lagos"
print(city)