Lesson 2
The Basic Elements
Chapter 7: Naming variables
How can I name my variables?
A variable name in Python:
- Can consist of letters, digits, or underscores (
_
) - Must start with a letter or an underscore
- Cannot be a reserved keyword (e.g.
True
orwhile
)
Variable names are also case-sensitive, so myvar
is not the same as MyVar
or MYVAR
>>> university = "Imperial"
>>> University = "College"
>>> UNIVERSITY = "London"
>>> print(university)
>>> print(University)
>>> print(UNIVERSITY)
Can you figure out which variable names below are valid? Test them out to confirm. Also, what error message will you receive (if any)?
❮
❯