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

Skip to content

Commit 53de190

Browse files
committed
Update ref docs on slicing.
1 parent aeaa546 commit 53de190

1 file changed

Lines changed: 13 additions & 30 deletions

File tree

Doc/reference/expressions.rst

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -513,14 +513,10 @@ or list). Slicings may be used as expressions or as targets in assignment or
513513
:keyword:`del` statements. The syntax for a slicing:
514514

515515
.. productionlist::
516-
slicing: `simple_slicing` | `extended_slicing`
517-
simple_slicing: `primary` "[" `short_slice` "]"
518-
extended_slicing: `primary` "[" `slice_list` "]"
516+
slicing: `primary` "[" `slice_list` "]"
519517
slice_list: `slice_item` ("," `slice_item`)* [","]
520518
slice_item: `expression` | `proper_slice`
521-
proper_slice: `short_slice` | `long_slice`
522-
short_slice: [`lower_bound`] ":" [`upper_bound`]
523-
long_slice: `short_slice` ":" [`stride`]
519+
proper_slice: [`lower_bound`] ":" [`upper_bound`] [ ":" [`stride`] ]
524520
lower_bound: `expression`
525521
upper_bound: `expression`
526522
stride: `expression`
@@ -530,36 +526,23 @@ expression list also looks like a slice list, so any subscription can be
530526
interpreted as a slicing. Rather than further complicating the syntax, this is
531527
disambiguated by defining that in this case the interpretation as a subscription
532528
takes priority over the interpretation as a slicing (this is the case if the
533-
slice list contains no proper slice). Similarly, when the slice list has
534-
exactly one short slice and no trailing comma, the interpretation as a simple
535-
slicing takes priority over that as an extended slicing.
536-
537-
.. XXX is the next paragraph stil correct?
538-
539-
The semantics for a simple slicing are as follows. The primary must evaluate to
540-
a sequence object. The lower and upper bound expressions, if present, must
541-
evaluate to plain integers; defaults are zero and the ``sys.maxint``,
542-
respectively. If either bound is negative, the sequence's length is added to
543-
it. The slicing now selects all items with index *k* such that ``i <= k < j``
544-
where *i* and *j* are the specified lower and upper bounds. This may be an
545-
empty sequence. It is not an error if *i* or *j* lie outside the range of valid
546-
indexes (such items don't exist so they aren't selected).
529+
slice list contains no proper slice).
547530

548531
.. index::
549532
single: start (slice object attribute)
550533
single: stop (slice object attribute)
551534
single: step (slice object attribute)
552535

553-
The semantics for an extended slicing are as follows. The primary must evaluate
554-
to a mapping object, and it is indexed with a key that is constructed from the
555-
slice list, as follows. If the slice list contains at least one comma, the key
556-
is a tuple containing the conversion of the slice items; otherwise, the
557-
conversion of the lone slice item is the key. The conversion of a slice item
558-
that is an expression is that expression. The conversion of a proper slice is a
559-
slice object (see section :ref:`types`) whose :attr:`start`, :attr:`stop` and
560-
:attr:`step` attributes are the values of the expressions given as lower bound,
561-
upper bound and stride, respectively, substituting ``None`` for missing
562-
expressions.
536+
The semantics for a slicing are as follows. The primary must evaluate to a
537+
mapping object, and it is indexed with a key that is constructed from the
538+
slice list, as follows. If the slice list contains at least one comma, the
539+
key is a tuple containing the conversion of the slice items; otherwise, the
540+
conversion of the lone slice item is the key. The conversion of a slice
541+
item that is an expression is that expression. The conversion of a proper
542+
slice is a slice object (see section :ref:`types`) whose :attr:`start`,
543+
:attr:`stop` and :attr:`step` attributes are the values of the expressions
544+
given as lower bound, upper bound and stride, respectively, substituting
545+
``None`` for missing expressions.
563546

564547

565548
.. _calls:

0 commit comments

Comments
 (0)