@@ -29,7 +29,7 @@ Arithmetic conversions
2929
3030When a description of an arithmetic operator below uses the phrase "the numeric
3131arguments are converted to a common type," this means that the operator
32- implementation for built-in types works that way :
32+ implementation for built-in types works as follows :
3333
3434* If either argument is a complex number, the other is converted to complex;
3535
@@ -38,8 +38,9 @@ implementation for built-in types works that way:
3838
3939* otherwise, both must be integers and no conversion is necessary.
4040
41- Some additional rules apply for certain operators (e.g., a string left argument
42- to the '%' operator). Extensions must define their own conversion behavior.
41+ Some additional rules apply for certain operators (e.g., a string as a left
42+ argument to the '%' operator). Extensions must define their own conversion
43+ behavior.
4344
4445
4546.. _atoms :
@@ -183,7 +184,7 @@ nesting from left to right, and evaluating the expression to produce an element
183184each time the innermost block is reached.
184185
185186Note that the comprehension is executed in a separate scope, so names assigned
186- to in the target list don't "leak" in the enclosing scope.
187+ to in the target list don't "leak" into the enclosing scope.
187188
188189
189190.. _lists :
@@ -293,7 +294,7 @@ for comprehensions, except that it is enclosed in parentheses instead of
293294brackets or curly braces.
294295
295296Variables used in the generator expression are evaluated lazily when the
296- :meth: `~generator.__next__ ` method is called for generator object (in the same
297+ :meth: `~generator.__next__ ` method is called for the generator object (in the same
297298fashion as normal generators). However, the leftmost :keyword: `for ` clause is
298299immediately evaluated, so that an error produced by it can be seen before any
299300other possible error in the code that handles the generator expression.
@@ -302,7 +303,7 @@ may depend on the previous :keyword:`for` loop. For example: ``(x*y for x in
302303range(10) for y in bar(x)) ``.
303304
304305The parentheses can be omitted on calls with only one argument. See section
305- :ref: `calls ` for the detail .
306+ :ref: `calls ` for details .
306307
307308
308309.. _yieldexpr :
@@ -327,12 +328,12 @@ When a generator function is called, it returns an iterator known as a
327328generator. That generator then controls the execution of a generator function.
328329The execution starts when one of the generator's methods is called. At that
329330time, the execution proceeds to the first yield expression, where it is
330- suspended again, returning the value of :token: `expression_list ` to generator's
331+ suspended again, returning the value of :token: `expression_list ` to the generator's
331332caller. By suspended, we mean that all local state is retained, including the
332333current bindings of local variables, the instruction pointer, and the internal
333334evaluation stack. When the execution is resumed by calling one of the
334335generator's methods, the function can proceed exactly as if the yield expression
335- was just another external call. The value of the yield expression after
336+ were just another external call. The value of the yield expression after
336337resuming depends on the method which resumed the execution. If
337338:meth: `~generator.__next__ ` is used (typically via either a :keyword: `for ` or
338339the :func: `next ` builtin) then the result is :const: `None `. Otherwise, if
@@ -344,10 +345,10 @@ that method.
344345All of this makes generator functions quite similar to coroutines; they yield
345346multiple times, they have more than one entry point and their execution can be
346347suspended. The only difference is that a generator function cannot control
347- where should the execution continue after it yields; the control is always
348+ where the execution should continue after it yields; the control is always
348349transferred to the generator's caller.
349350
350- yield expressions are allowed in the :keyword: `try ` clause of a :keyword: `try `
351+ Yield expressions are allowed in the :keyword: `try ` clause of a :keyword: `try `
351352... :keyword: `finally ` construct. If the generator is not resumed before it is
352353finalized (by reaching a zero reference count or by being garbage collected),
353354the generator-iterator's :meth: `~generator.close ` method will be called,
@@ -430,7 +431,7 @@ is already executing raises a :exc:`ValueError` exception.
430431
431432.. method :: generator.throw(type[, value[, traceback]])
432433
433- Raises an exception of type ``type `` at the point where generator was paused,
434+ Raises an exception of type ``type `` at the point where the generator was paused,
434435 and returns the next value yielded by the generator function. If the generator
435436 exits without yielding another value, a :exc: `StopIteration ` exception is
436437 raised. If the generator function does not catch the passed-in exception, or
@@ -520,11 +521,11 @@ An attribute reference is a primary followed by a period and a name:
520521
521522The primary must evaluate to an object of a type that supports attribute
522523references, which most objects do. This object is then asked to produce the
523- attribute whose name is the identifier (which can be customized by overriding
524- the :meth: `__getattr__ ` method). If this attribute is not available, the
525- exception :exc: `AttributeError ` is raised. Otherwise, the type and value of the
526- object produced is determined by the object. Multiple evaluations of the same
527- attribute reference may yield different objects.
524+ attribute whose name is the identifier. This production can be customized by
525+ overriding the :meth: `__getattr__ ` method). If this attribute is not available,
526+ the exception :exc: `AttributeError ` is raised. Otherwise, the type and value of
527+ the object produced is determined by the object. Multiple evaluations of the
528+ same attribute reference may yield different objects.
528529
529530
530531.. _subscriptions :
@@ -549,9 +550,9 @@ A subscription selects an item of a sequence (string, tuple or list) or mapping
549550.. productionlist ::
550551 subscription: `primary ` "[" `expression_list ` "]"
551552
552- The primary must evaluate to an object that supports subscription, e.g. a list
553- or dictionary . User-defined objects can support subscription by defining a
554- :meth: `__getitem__ ` method.
553+ The primary must evaluate to an object that supports subscription (lists or
554+ dictionaries for example) . User-defined objects can support subscription by
555+ defining a :meth: `__getitem__ ` method.
555556
556557For built-in objects, there are two types of objects that support subscription:
557558
@@ -660,8 +661,8 @@ series of :term:`arguments <argument>`:
660661 keyword_arguments: `keyword_item ` ("," `keyword_item `)*
661662 keyword_item: `identifier ` "=" `expression `
662663
663- A trailing comma may be present after the positional and keyword arguments but
664- does not affect the semantics.
664+ An optional trailing comma may be present after the positional and keyword arguments
665+ but does not affect the semantics.
665666
666667.. index ::
667668 single: parameter; call semantics
@@ -943,9 +944,9 @@ point number using the :func:`abs` function if appropriate.
943944.. index :: single: addition
944945
945946The ``+ `` (addition) operator yields the sum of its arguments. The arguments
946- must either both be numbers or both sequences of the same type. In the former
947- case, the numbers are converted to a common type and then added together. In
948- the latter case, the sequences are concatenated.
947+ must either both be numbers or both be sequences of the same type. In the
948+ former case, the numbers are converted to a common type and then added together.
949+ In the latter case, the sequences are concatenated.
949950
950951.. index :: single: subtraction
951952
@@ -1106,7 +1107,7 @@ Comparison of objects of the same type depends on the type:
11061107 another one is made arbitrarily but consistently within one execution of a
11071108 program.
11081109
1109- Comparison of objects of the differing types depends on whether either of the
1110+ Comparison of objects of differing types depends on whether either of the
11101111types provide explicit support for the comparison. Most numeric types can be
11111112compared with one another. When cross-type comparison is not supported, the
11121113comparison method returns ``NotImplemented ``.
@@ -1116,7 +1117,7 @@ comparison method returns ``NotImplemented``.
11161117The operators :keyword: `in ` and :keyword: `not in ` test for membership. ``x in
11171118s `` evaluates to true if *x * is a member of *s *, and false otherwise. ``x not
11181119in s `` returns the negation of ``x in s ``. All built-in sequences and set types
1119- support this as well as dictionary, for which :keyword: `in ` tests whether a the
1120+ support this as well as dictionary, for which :keyword: `in ` tests whether the
11201121dictionary has a given key. For container types such as list, tuple, set,
11211122frozenset, dict, or collections.deque, the expression ``x in y `` is equivalent
11221123to ``any(x is e or x == e for e in y) ``.
@@ -1202,9 +1203,9 @@ returned; otherwise, *y* is evaluated and the resulting value is returned.
12021203they return to ``False `` and ``True ``, but rather return the last evaluated
12031204argument. This is sometimes useful, e.g., if ``s `` is a string that should be
12041205replaced by a default value if it is empty, the expression ``s or 'foo' `` yields
1205- the desired value. Because :keyword: `not ` has to invent a value anyway , it does
1206- not bother to return a value of the same type as its argument, so e.g., `` not
1207- 'foo' `` yields ``False ``, not ``'' ``.)
1206+ the desired value. Because :keyword: `not ` has to create a new value , it
1207+ returns a boolean value regardless of the type of its argument
1208+ (for example, `` not 'foo' `` produces ``False `` rather than ``'' ``.)
12081209
12091210
12101211Conditional expressions
@@ -1222,8 +1223,8 @@ Conditional expressions
12221223Conditional expressions (sometimes called a "ternary operator") have the lowest
12231224priority of all Python operations.
12241225
1225- The expression ``x if C else y `` first evaluates the condition, *C * (* not * *x *);
1226- if *C * is true, *x * is evaluated and its value is returned; otherwise, *y * is
1226+ The expression ``x if C else y `` first evaluates the condition, *C * rather than *x *.
1227+ If *C * is true, *x * is evaluated and its value is returned; otherwise, *y * is
12271228evaluated and its value is returned.
12281229
12291230See :pep: `308 ` for more details about conditional expressions.
@@ -1244,10 +1245,9 @@ Lambdas
12441245 lambda_expr: "lambda" [`parameter_list `]: `expression `
12451246 lambda_expr_nocond: "lambda" [`parameter_list `]: `expression_nocond `
12461247
1247- Lambda expressions (sometimes called lambda forms) have the same syntactic position as
1248- expressions. They are a shorthand to create anonymous functions; the expression
1249- ``lambda arguments: expression `` yields a function object. The unnamed object
1250- behaves like a function object defined with ::
1248+ Lambda expressions (sometimes called lambda forms) are create anonymous
1249+ functions. The expression ``lambda arguments: expression `` yields a function
1250+ object. The unnamed object behaves like a function object defined with ::
12511251
12521252 def <lambda>(arguments):
12531253 return expression
@@ -1310,13 +1310,15 @@ Operator precedence
13101310
13111311.. index :: pair: operator; precedence
13121312
1313- The following table summarizes the operator precedences in Python, from lowest
1313+ The following table summarizes the operator precedence in Python, from lowest
13141314precedence (least binding) to highest precedence (most binding). Operators in
13151315the same box have the same precedence. Unless the syntax is explicitly given,
13161316operators are binary. Operators in the same box group left to right (except for
1317- comparisons, including tests, which all have the same precedence and chain from
1318- left to right --- see section :ref: `comparisons ` --- and exponentiation, which
1319- groups from right to left).
1317+ exponentiation, which groups from right to left).
1318+
1319+ Note that comparisons, membership tests, and identity tests, all have the same
1320+ precedence and have a left-to-right chaining feature as described in the
1321+ :ref: `comparisons ` section.
13201322
13211323
13221324+-----------------------------------------------+-------------------------------------+
0 commit comments