2.8 Programming Page 8
Completion requirements
Variables:
Python offers special βboxesβ (containers) to store data called variables. The name suggests that the content of these containers can be varied in (almost) any way.
Every Python variable has:
- a name
- a value (the content of the container)
Rules for naming variables:
- The name of the variable must be composed of upper-case or lower-case letters, digits, and the character underscore (underscore).
- The name of the variable must begin with a letter.
- The underscore character is a letter.
- Upper- and lower-case letters are treated as different
(This is a little different than in usual writing where Alice and ALICE are the
same first names. In Python, they are two different variable names,
and consequently, two different variables.
- The name of the variable must not be any of Pythonβs reserved words , such as print. (These are keywords, which will be explained more soon).
Keywords that should not be used as variable names:
Python
does not impose restrictions on the length of variable names, but a short variable name is preferred to a long one. Short, clear and descriptive is always best!