1.2.1.6 PCEP-30-02 Practice Test Compendium – Variables, assignments, comments
Last updated
Last updated
01) A variable is a named container able to store data.
02) A variable's name can consist of:
letters (including non-Latin ones)
digits
underscores (_
)
and must start with a letter (note: underscores count as letters). Upper- and lower-case letters are treated as different.
03) Variable names which start with underscores play a specific role in Python – don't use them unless you know what you're doing.
04) Variable names are not limited in length.
05) The name of the variable must not be any of Python's keywords (also known as reserved words). The complete list of Python 3.8 keywords looks as follows:
* Note: Python 3.9 introduced a new keyword, __peg_parser__
, which is an easter egg related to the rollout of a new PEG parser for CPython. You can read more about this in . The keyword will most probably be removed in Python 3.10.
06) These are some legal, but not necessarily the best, Python variable names:
i
counter_2
_
Tax22
07) The assignment operator =
is designed to assign a value to a variable:
For example:
or – when more than one variable is assigned with the same value:
For example:
08) A variable must be assigned (defined) before its first use – using a variable without prior definition (assignment) raises the NameError
exception.
09) Python is a dynamically typed language, which means that a variable can freely change its type according to the last assignment it took part in.
10) There are some short-cut (compound) operators which simplify certain kinds of assignments.