mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-01-17 21:49:22 +01:00
Merge pull request #536 from markwhiting/patch-1
Better explanation of list slices
This commit is contained in:
commit
ccd0f09ea5
@ -160,8 +160,12 @@ li[1:3] #=> [2, 4]
|
||||
li[2:] #=> [4, 3]
|
||||
# Omit the end
|
||||
li[:3] #=> [1, 2, 4]
|
||||
# Select every second entry
|
||||
li[::2] #=>[1,4]
|
||||
# Revert the list
|
||||
li[::-1] #=> [3, 4, 2, 1]
|
||||
# Use any combination of these to make advanced slices
|
||||
# li[start:end:step]
|
||||
|
||||
# Remove arbitrary elements from a list with "del"
|
||||
del li[2] # li is now [1, 2, 3]
|
||||
|
Loading…
x
Reference in New Issue
Block a user