+91 81900 98289

Variable Names

This Variable Names lesson is for a beginner. Read the short notes, run each example, then change one name or number and run it again.

A name starts with a letter or an underscore. Digits can follow. Spaces, hyphens, and a leading digit are not allowed.

city and City are two different names. Python keywords such as class, for, and if cannot be used as names.

Example 1: Start here

A short name is fine for a loop. A stored value deserves a name you can read later.

batch_size = 24 # a whole number print(batch_size)

Example 2: Use a readable name

Underscores are allowed. Spaces are not.

batch_size = 24 # a whole number print(batch_size)

Example 3: Case makes a new name

city and City are different names.

city = "Chennai" # text City = "Pune" # text print(city) print(City)

Example 4: A name can hold a list

The name is on the left. The list is the value on the right.

scores = [80, 90] # a list; the values stay in this order print(scores)
A short name is fine for a loop. A stored value deserves a name you can read later.
Call Now 81900 98289