Variables ¶
In programming languages, variables play a crucial role as they serve as labels for storing and manipulating data. A variable is essentially a symbolic name or identifier associated with a memory location that holds a value. These values can be numbers, characters, strings, or more complex data structures.
These are no different than variables in math. If I give you an equation $x + y$ and then tell you $x = 1$ and $y = 3$, you mentally put these numbers in the equation and get $1 + 3$. In fact, that is all valid Python!
x = 1
y = 3
print(x + y)
4
This essentially is communicating to Python the same thing I was to you.
You are saying: Hey Python, whenever you see
x
after this line, put 1 there. For
y
, put 3.
However, you have to tell Python about
x
and
y
before you use them.
Like I said before,
computers are dumb
.
If you tried to tell it about the equation
x + y
first, Python would panic because
x
and
y
don't exist yet.
We will discuss this more
later
.