Created
November 3, 2016 04:24
-
-
Save bolerap/736739edb57a3deba50209e19706d96a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = [1, 2, 3, 4, 5] | |
# slice [start:end] | |
print(a[1:3]) # [2 3] | |
print(a[-3: -1]) # [3, 4] | |
# slice [start:end:step] | |
print(a[::2]) # [1 3 5] | |
print(a[::-1]) # [5 4 3 2 1] | |
# slice assignment | |
a[1:-1] = [] | |
print(a) # [1, 5] | |
# naming slice | |
b = list(range(5)) | |
last_two = a[-2:] | |
print(b[last_two]) # [4, 5] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment