6. 運算式¶
This chapter explains the meaning of the elements of expressions in Python.
Syntax Notes: In this and the following chapters, grammar notation will be used to describe syntax, not lexical analysis.
When (one alternative of) a syntax rule has the form:
name: othername
and no semantics are given, the semantics of this form of name are the same
as for othername.
6.1. Arithmetic conversions¶
When a description of an arithmetic operator below uses the phrase "the numeric arguments are converted to a common real type", this means that the operator implementation for built-in numeric types works as described in the Numeric Types section of the standard library documentation.
Some additional rules apply for certain operators and non-numeric operands
(for example, a string as a left argument to the % operator).
Extensions must define their own conversion behavior.
6.2. Atoms¶
Atoms are the most basic elements of expressions. The simplest atoms are names or literals. Forms enclosed in parentheses, brackets or braces are also categorized syntactically as atoms.
Formally, the syntax for atoms is:
atom: | 'True' | 'False' | 'None' | '...' |identifier|literal|enclosureenclosure: |parenth_form|list_display|dict_display|set_display|generator_expression|yield_atom
6.2.1. 內建常數¶
The keywords True, False, and