Your tracker prints a title and a month, typed straight into each print. This lesson stores them under names first. Once a value has a name, your program can reuse it and change it.
The concept
Here is your tracker as the last lesson left it. Run it:
The "where you left off" boxes show the starting version. Your own tracker, with your name in it, is safe in the exercise at the end of this page.
Now run this:
You typed November 2026 once, and it printed twice. The first line stored the string under the name month. Each print(month) looked that name up and printed what it held. A name that holds a value is called a variable.
A variable can be given a new value. Run this:
Two different lines from the same print(status). The third line replaced the value stored under status. Python runs top to bottom, so the first print ran before the change and the second ran after it.
The syntax
month = "November 2026"The name goes on the left, the value goes on the right, and = sits between them. Storing a value this way is called assignment.
In Python, = does not mean "is equal to". It is an instruction: store the value on the right under the name on the left. That is why the order matters. "November 2026" = month is an error, because a string cannot be used as a name.
To use a variable, write its name without quotes. print(month) prints the value stored in month. print("month") prints the word month, because the quotes make it a string.
Names follow three rules:
- Use letters, digits and underscores only. No spaces, no dashes.
- Do not start with a digit.
month2works.2monthdoes not. - Capitals count.
monthandMonthare two different names.
Python programmers write names in lowercase, with underscores between words: bus_fare, data_bundle. This style is called snake case. Python does not require it, but every example in this track uses it.
Blank lines between groups of code change nothing. They are there to make the code easier to read.
A minimal working example
title = "Ada's Money Tracker"
month = "November 2026"
print(title)
print(month)Two variables, assigned at the top, used by the prints below them. The output is the same as typing the text into each print. The difference is that the text now has a name.
Common mistakes
You use a name before the line that assigns it. Run this:
NameError: name 'month' is not definedPython runs line 1 first. At that moment nothing has been stored under month yet. "Not defined" means "no value has been assigned to this name so far". Move the assignment above the line that uses it.
You put a space or a dash in a name. my month = "November 2026" gives SyntaxError: invalid syntax. this-month = "November 2026" gives SyntaxError: cannot assign to expression here, because Python reads the dash as a minus sign. Use an underscore: this_month.
You start a name with a digit. 2026month = "November" gives SyntaxError: invalid decimal literal. Python saw digits and expected a number. Put the digits later: month_2026.
You change the case of one letter. Run this:
NameError: name 'Month' is not defined. Did you mean: 'month'?To Python, Month is a different name, and nothing was assigned to it. Read the end of the error: Python spotted the near match and suggested it.
Try it yourself
You will move the text in your tracker into variables. The output should stay exactly the same while you do it. That is how you know the variables hold the right values.
- Run the starting code below. Confirm the console shows your title, the month, a blank line, then
Nothing spent yet. - Add a new first line:
title =followed by your title in quotes, exactly as it appears in your firstprint. Change thatprinttoprint(title). Run it. Confirm the output has not changed. - Under the
titleline, addmonth = "November 2026", or your own month. Change the secondprinttoprint(month). Run it. Confirm the output has not changed. - Under that, add
status = "Nothing spent yet". Change the lastprinttoprint(status). Leave a blank line between your three variables and your prints. Run it. Confirm the output has not changed. - Replace a value: on the line after
status = "Nothing spent yet", addstatus = "Spending started". Run it. Confirm the last line now readsSpending started. Then delete that line and Run again to bringNothing spent yetback. - Break it on purpose: change
print(month)toprint(Month)with a capital M. Run it. Confirm your title printed, then aNameErrorthat suggests'month'. Nothing after the error printed. - Fix it: make the M lowercase again. Run it. Confirm all four lines return.
Your tracker's text now lives in variables. Every value in it is still text, though. The next lesson adds the first numbers to your tracker: what you spent.