Syntax: atoms
Atoms are the most basic elements of expressions. The simplest atoms are identifiers or literals. Subexpressions enclosed in reverse quotes or in parentheses, brackets or braces are also categorized syntactically as atoms.
- Identifiers (see below)
- Literals (see below)
- parenthesized-forms
- list-displays
- generator-expressions
- dictionary-displays
- string-conversions
Identifiers (Names) #
An identifier occurring as an atom is a name. See naming-and-binding for documentation of naming and binding.
When the name is bound to an object, evaluation of the atom yields that object. When a name is not bound, an attempt to evaluate it raises a NameError exception.
Private name mangling: When an identifier that textually occurs in
a class definition begins with two or more underscore characters and
does not end in two or more underscores, it is considered a private
name of that class. Private names are transformed to a longer form
before code is generated for them. The transformation inserts the
class name in front of the name, with leading underscores removed, and
a single underscore inserted in front of the class name. For example,
the identifier \_\_spam occurring in a class named Ham will be
transformed to \_Ham\_\_spam. This transformation is independent of
the syntactical context in which the identifier is used. If the
transformed name is extremely long (longer than 255 characters),
implementation defined truncation may happen. If the class name
consists only of underscores, no transformation is done.
Literals #
Python supports string literals and various numeric literals:
literal ::= [ stringliteral][1] | [integer][2] | [ longinteger][3]
| [floatnumber][4] | [ imagnumber][5]
Evaluation of a literal yields an object of the given type (string, integer, long integer, floating point number, complex number) with the given value. The value may be approximated in the case of floating point and imaginary (complex) literals. See literals for details.
All literals correspond to immutable data types, and hence the object’s identity is less important than its value. Multiple evaluations of literals with the same value (either the same occurrence in the program text or a different occurrence) may obtain the same object or a different object with the same value.