Slicings

A slicing selects a range of items in a sequence object (e.g., a string, tuple or list). Slicings may be used as expressions or as targets in assignment or del statements. The syntax for a slicing:

Syntax:

primary []

slicing ::= [simple_slicing][1] | [ extended_slicing][2] simple_slicing ::= [ primary][3] “[” [short_slice][4] “]” extended_slicing ::= [ primary][3] “[” [slice_list][5] “]” slice_list ::= [ slice_item][6] (“,” [slice_item][6])* [“,”] slice_item ::= [ expression][7] | [proper_slice][8] | [ ellipsis][9] proper_slice ::= [ short_slice][4] | [long_slice][10] short_slice ::= [[lower_bound][11]] “:” [[upper_bound][12]] long_slice ::= [ short_slice][4] “:” [[stride][13]] lower_bound ::= [ expression][7] upper_bound ::= [ expression][7] stride ::= [ expression][7] ellipsis ::= “…”

There is ambiguity in the formal syntax here: anything that looks like an expression list also looks like a slice list, so any subscription can be interpreted as a slicing. Rather than further complicating the syntax, this is disambiguated by defining that in this case the interpretation as a subscription takes priority over the interpretation as a slicing (this is the case if t