Variables
What are variables?
Variables in Python are names for values. For example, if you have the number 5
or the string "Rolf"
, you can give them a name.
That way you can refer to those values later on in your program, and you can change them as your program runs.
Variables are one of the fundamental parts of programming, so we'll be using them very extensively!
How do you declare a variable?
In Python we declare variables by specifying:
- The name of the variable.
- An equal sign.
- The value of the variable.
Such as this string variable:
name = "Rolf"
Or this integer variable:
age = 30
Names of variables can contain underscores (_
), numbers, and letters. They cannot start with a number.
Extra resources
We've written a blog post about this for extra reading: http://blog.tecladocode.com/learn-python-day-3-first-look-at-python/
RealPython also has an excellent collection of blog posts, their one on variables is fairly long but detailed and comprehensive: https://realpython.com/python-variables/