Created
July 28, 2020 14:15
-
-
Save FerdinaKusumah/26f3f8d850fbdb96b7baedd7562353a4 to your computer and use it in GitHub Desktop.
[Python] Array Slice
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
"""Slice array""" | |
num = [1, 2, 3, 4, 5, 6, 7] | |
"""Get all array except first value""" | |
val_1 = num[1::] | |
# val 1 is [2, 3, 4, 5, 6, 7] | |
"""Get all array except last value""" | |
val_2 = num[:-1] | |
# val 2 is [1, 2, 3, 4, 5, 6] | |
"""Get only last value""" | |
val_3 = num[-1] | |
# val 3 is 7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment