Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a73a34d

Browse files
committed
merge
2 parents 07e0485 + aa7886d commit a73a34d

5 files changed

Lines changed: 102 additions & 84 deletions

File tree

Doc/reference/compound_stmts.rst

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ also syntactically compound statements.
2222
single: clause
2323
single: suite
2424

25-
Compound statements consist of one or more 'clauses.' A clause consists of a
25+
A compound statement consists of one or more 'clauses.' A clause consists of a
2626
header and a 'suite.' The clause headers of a particular compound statement are
2727
all at the same indentation level. Each clause header begins with a uniquely
2828
identifying keyword and ends with a colon. A suite is a group of statements
2929
controlled by a clause. A suite can be one or more semicolon-separated simple
3030
statements on the same line as the header, following the header's colon, or it
3131
can be one or more indented statements on subsequent lines. Only the latter
32-
form of suite can contain nested compound statements; the following is illegal,
32+
form of a suite can contain nested compound statements; the following is illegal,
3333
mostly because it wouldn't be clear to which :keyword:`if` clause a following
3434
:keyword:`else` clause would belong::
3535

@@ -156,8 +156,8 @@ The :keyword:`for` statement is used to iterate over the elements of a sequence
156156

157157
The expression list is evaluated once; it should yield an iterable object. An
158158
iterator is created for the result of the ``expression_list``. The suite is
159-
then executed once for each item provided by the iterator, in the order of
160-
ascending indices. Each item in turn is assigned to the target list using the
159+
then executed once for each item provided by the iterator, in the order returned
160+
by the iterator. Each item in turn is assigned to the target list using the
161161
standard rules for assignments (see :ref:`assignment`), and then the suite is
162162
executed. When the items are exhausted (which is immediately when the sequence
163163
is empty or an iterator raises a :exc:`StopIteration` exception), the suite in
@@ -170,17 +170,25 @@ the :keyword:`else` clause, if present, is executed, and the loop terminates.
170170
A :keyword:`break` statement executed in the first suite terminates the loop
171171
without executing the :keyword:`else` clause's suite. A :keyword:`continue`
172172
statement executed in the first suite skips the rest of the suite and continues
173-
with the next item, or with the :keyword:`else` clause if there was no next
173+
with the next item, or with the :keyword:`else` clause if there is no next
174174
item.
175175

176-
The suite may assign to the variable(s) in the target list; this does not affect
177-
the next item assigned to it.
176+
The for-loop makes assignments to the variables(s) in the target list.
177+
This overwrites all previous assignments to those variables including
178+
those made in the suite of the for-loop::
179+
180+
for i in range(10):
181+
print(i)
182+
i = 5 # this will not affect the for-loop
183+
# be i will be overwritten with the next
184+
# index in the range
185+
178186

179187
.. index::
180188
builtin: range
181189

182190
Names in the target list are not deleted when the loop is finished, but if the
183-
sequence is empty, it will not have been assigned to at all by the loop. Hint:
191+
sequence is empty, they will not have been assigned to at all by the loop. Hint:
184192
the built-in function :func:`range` returns an iterator of integers suitable to
185193
emulate the effect of Pascal's ``for i := a to b do``; e.g., ``list(range(3))``
186194
returns the list ``[0, 1, 2]``.
@@ -284,7 +292,7 @@ keeping all locals in that frame alive until the next garbage collection occurs.
284292
object: traceback
285293

286294
Before an except clause's suite is executed, details about the exception are
287-
stored in the :mod:`sys` module and can be access via :func:`sys.exc_info`.
295+
stored in the :mod:`sys` module and can be accessed via :func:`sys.exc_info`.
288296
:func:`sys.exc_info` returns a 3-tuple consisting of the exception class, the
289297
exception instance and a traceback object (see section :ref:`types`) identifying
290298
the point in the program where the exception occurred. :func:`sys.exc_info`
@@ -461,7 +469,7 @@ A function definition defines a user-defined function object (see section
461469
decorator: "@" `dotted_name` ["(" [`parameter_list` [","]] ")"] NEWLINE
462470
dotted_name: `identifier` ("." `identifier`)*
463471
parameter_list: (`defparameter` ",")*
464-
: ( "*" [`parameter`] ("," `defparameter`)* ["," "**" `parameter`]
472+
: | "*" [`parameter`] ("," `defparameter`)* ["," "**" `parameter`]
465473
: | "**" `parameter`
466474
: | `defparameter` [","] )
467475
parameter: `identifier` [":" `expression`]

Doc/reference/datamodel.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ are still reachable.
7777
module for information on controlling the collection of cyclic garbage.
7878
Other implementations act differently and CPython may change.
7979
Do not depend on immediate finalization of objects when they become
80-
unreachable (ex: always close files).
80+
unreachable (so you should always close files explicitly).
8181

8282
Note that the use of the implementation's tracing or debugging facilities may
8383
keep objects alive that would normally be collectable. Also note that catching
@@ -1722,7 +1722,7 @@ property creation, proxies, frameworks, and automatic resource
17221722
locking/synchronization.
17231723

17241724
Here is an example of a metaclass that uses an :class:`collections.OrderedDict`
1725-
to remember the order that class members were defined::
1725+
to remember the order that class variables are defined::
17261726

17271727
class OrderedClass(type):
17281728

Doc/reference/executionmodel.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ that name established in the innermost function block containing the use.
3131
A :dfn:`block` is a piece of Python program text that is executed as a unit.
3232
The following are blocks: a module, a function body, and a class definition.
3333
Each command typed interactively is a block. A script file (a file given as
34-
standard input to the interpreter or specified on the interpreter command line
35-
the first argument) is a code block. A script command (a command specified on
36-
the interpreter command line with the '**-c**' option) is a code block. The
37-
string argument passed to the built-in functions :func:`eval` and :func:`exec`
38-
is a code block.
34+
standard input to the interpreter or specified as a command line argument to the
35+
interpreter) is a code block. A script command (a command specified on the
36+
interpreter command line with the '**-c**' option) is a code block. The string
37+
argument passed to the built-in functions :func:`eval` and :func:`exec` is a
38+
code block.
3939

4040
.. index:: pair: execution; frame
4141

@@ -77,7 +77,7 @@ global.) If a variable is used in a code block but not defined there, it is a
7777
single: UnboundLocalError
7878

7979
When a name is not found at all, a :exc:`NameError` exception is raised. If the
80-
name refers to a local variable that has not been bound, a
80+
name refers to a local variable that has not been bound, an
8181
:exc:`UnboundLocalError` exception is raised. :exc:`UnboundLocalError` is a
8282
subclass of :exc:`NameError`.
8383

Doc/reference/expressions.rst

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Arithmetic conversions
2929

3030
When a description of an arithmetic operator below uses the phrase "the numeric
3131
arguments 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
183184
each time the innermost block is reached.
184185

185186
Note 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
293294
brackets or curly braces.
294295

295296
Variables 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
297298
fashion as normal generators). However, the leftmost :keyword:`for` clause is
298299
immediately evaluated, so that an error produced by it can be seen before any
299300
other 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
302303
range(10) for y in bar(x))``.
303304

304305
The 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
327328
generator. That generator then controls the execution of a generator function.
328329
The execution starts when one of the generator's methods is called. At that
329330
time, 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
331332
caller. By suspended, we mean that all local state is retained, including the
332333
current bindings of local variables, the instruction pointer, and the internal
333334
evaluation stack. When the execution is resumed by calling one of the
334335
generator'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
336337
resuming depends on the method which resumed the execution. If
337338
:meth:`~generator.__next__` is used (typically via either a :keyword:`for` or
338339
the :func:`next` builtin) then the result is :const:`None`. Otherwise, if
@@ -344,10 +345,10 @@ that method.
344345
All of this makes generator functions quite similar to coroutines; they yield
345346
multiple times, they have more than one entry point and their execution can be
346347
suspended. 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
348349
transferred 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
352353
finalized (by reaching a zero reference count or by being garbage collected),
353354
the 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

521522
The primary must evaluate to an object of a type that supports attribute
522523
references, 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

556557
For 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
@@ -951,9 +952,9 @@ point number using the :func:`abs` function if appropriate.
951952
.. index:: single: addition
952953

953954
The ``+`` (addition) operator yields the sum of its arguments. The arguments
954-
must either both be numbers or both sequences of the same type. In the former
955-
case, the numbers are converted to a common type and then added together. In
956-
the latter case, the sequences are concatenated.
955+
must either both be numbers or both be sequences of the same type. In the
956+
former case, the numbers are converted to a common type and then added together.
957+
In the latter case, the sequences are concatenated.
957958

958959
.. index:: single: subtraction
959960

@@ -1114,7 +1115,7 @@ Comparison of objects of the same type depends on the type:
11141115
another one is made arbitrarily but consistently within one execution of a
11151116
program.
11161117

1117-
Comparison of objects of the differing types depends on whether either of the
1118+
Comparison of objects of differing types depends on whether either of the
11181119
types provide explicit support for the comparison. Most numeric types can be
11191120
compared with one another. When cross-type comparison is not supported, the
11201121
comparison method returns ``NotImplemented``.
@@ -1124,7 +1125,7 @@ comparison method returns ``NotImplemented``.
11241125
The operators :keyword:`in` and :keyword:`not in` test for membership. ``x in
11251126
s`` evaluates to true if *x* is a member of *s*, and false otherwise. ``x not
11261127
in s`` returns the negation of ``x in s``. All built-in sequences and set types
1127-
support this as well as dictionary, for which :keyword:`in` tests whether a the
1128+
support this as well as dictionary, for which :keyword:`in` tests whether the
11281129
dictionary has a given key. For container types such as list, tuple, set,
11291130
frozenset, dict, or collections.deque, the expression ``x in y`` is equivalent
11301131
to ``any(x is e or x == e for e in y)``.
@@ -1210,9 +1211,9 @@ returned; otherwise, *y* is evaluated and the resulting value is returned.
12101211
they return to ``False`` and ``True``, but rather return the last evaluated
12111212
argument. This is sometimes useful, e.g., if ``s`` is a string that should be
12121213
replaced by a default value if it is empty, the expression ``s or 'foo'`` yields
1213-
the desired value. Because :keyword:`not` has to invent a value anyway, it does
1214-
not bother to return a value of the same type as its argument, so e.g., ``not
1215-
'foo'`` yields ``False``, not ``''``.)
1214+
the desired value. Because :keyword:`not` has to create a new value, it
1215+
returns a boolean value regardless of the type of its argument
1216+
(for example, ``not 'foo'`` produces ``False`` rather than ``''``.)
12161217

12171218

12181219
Conditional expressions
@@ -1230,8 +1231,8 @@ Conditional expressions
12301231
Conditional expressions (sometimes called a "ternary operator") have the lowest
12311232
priority of all Python operations.
12321233

1233-
The expression ``x if C else y`` first evaluates the condition, *C* (*not* *x*);
1234-
if *C* is true, *x* is evaluated and its value is returned; otherwise, *y* is
1234+
The expression ``x if C else y`` first evaluates the condition, *C* rather than *x*.
1235+
If *C* is true, *x* is evaluated and its value is returned; otherwise, *y* is
12351236
evaluated and its value is returned.
12361237

12371238
See :pep:`308` for more details about conditional expressions.
@@ -1252,10 +1253,9 @@ Lambdas
12521253
lambda_expr: "lambda" [`parameter_list`]: `expression`
12531254
lambda_expr_nocond: "lambda" [`parameter_list`]: `expression_nocond`
12541255

1255-
Lambda expressions (sometimes called lambda forms) have the same syntactic position as
1256-
expressions. They are a shorthand to create anonymous functions; the expression
1257-
``lambda arguments: expression`` yields a function object. The unnamed object
1258-
behaves like a function object defined with ::
1256+
Lambda expressions (sometimes called lambda forms) are create anonymous
1257+
functions. The expression ``lambda arguments: expression`` yields a function
1258+
object. The unnamed object behaves like a function object defined with ::
12591259

12601260
def <lambda>(arguments):
12611261
return expression
@@ -1318,13 +1318,15 @@ Operator precedence
13181318

13191319
.. index:: pair: operator; precedence
13201320

1321-
The following table summarizes the operator precedences in Python, from lowest
1321+
The following table summarizes the operator precedence in Python, from lowest
13221322
precedence (least binding) to highest precedence (most binding). Operators in
13231323
the same box have the same precedence. Unless the syntax is explicitly given,
13241324
operators are binary. Operators in the same box group left to right (except for
1325-
comparisons, including tests, which all have the same precedence and chain from
1326-
left to right --- see section :ref:`comparisons` --- and exponentiation, which
1327-
groups from right to left).
1325+
exponentiation, which groups from right to left).
1326+
1327+
Note that comparisons, membership tests, and identity tests, all have the same
1328+
precedence and have a left-to-right chaining feature as described in the
1329+
:ref:`comparisons` section.
13281330

13291331

13301332
+-----------------------------------------------+-------------------------------------+

0 commit comments

Comments
 (0)