mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
Merge pull request #3630 from divayprakash/fix-python
[python3/en] Fix explanation for slices, closes #3629
This commit is contained in:
commit
dff76c7965
@ -228,15 +228,11 @@ li[4] # Raises an IndexError
|
|||||||
# You can look at ranges with slice syntax.
|
# You can look at ranges with slice syntax.
|
||||||
# The start index is included, the end index is not
|
# The start index is included, the end index is not
|
||||||
# (It's a closed/open range for you mathy types.)
|
# (It's a closed/open range for you mathy types.)
|
||||||
li[1:3] # => [2, 4]
|
li[1:3] # Return list from index 1 to 3 => [2, 4]
|
||||||
# Omit the beginning and return the list
|
li[2:] # Return list starting from index 2 => [4, 3]
|
||||||
li[2:] # => [4, 3]
|
li[:3] # Return list from beginning uptil index 3 => [1, 2, 4]
|
||||||
# Omit the end and return the list
|
li[::2] # Return list selecting every second entry => [1, 4]
|
||||||
li[:3] # => [1, 2, 4]
|
li[::-1] # Return list in reverse order => [3, 4, 2, 1]
|
||||||
# Select every second entry
|
|
||||||
li[::2] # =>[1, 4]
|
|
||||||
# Return a reversed copy of the list
|
|
||||||
li[::-1] # => [3, 4, 2, 1]
|
|
||||||
# Use any combination of these to make advanced slices
|
# Use any combination of these to make advanced slices
|
||||||
# li[start:end:step]
|
# li[start:end:step]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user