variable: a named unit of computer memory that can store a value
They're kind of like cells in a spreadsheet
Cell with name B4 has the value 42, and we can use that value in other computations by referring to its name.
In Python, we can do something similar.
B4 = 42
B5 = B4+10
print(B4)
print(B5)
We can give variables any name we want
foo = 42
bar = foo + 10
print(bar)
But... you should give them descriptive names for the sake of humans reading the code
num_students = 42
num_adults = 10
total_field_trip_lunches = num_students + num_adults
print(total_field_trip_lunches)
Allowed: upper and lowercase letters, numbers, underscores _
Not Allowed: other special characters, spaces
total$ = 42.0
Can't start with a number
5th_grade_students = 42
Names a case-sensitive (lower/uppercase matters)
students = 42
print(Students)
Code with a = is called an assignment statement
students = 42
Whatever is on the right side of = will be evaluated and saved to the variable named on the left side.
You can't write it the other way around.
42 = students
We've seen printing out text by itself and variables by themselves. What if I want both in the same print statement?
You can pass multiple things to print() using commas between them.
students = 42
print("There are",students,"students who need to eat lunch.")