Skip to content

Instantly share code, notes, and snippets.

@FerdinaKusumah
Created July 28, 2020 14:15
Show Gist options
  • Save FerdinaKusumah/26f3f8d850fbdb96b7baedd7562353a4 to your computer and use it in GitHub Desktop.
Save FerdinaKusumah/26f3f8d850fbdb96b7baedd7562353a4 to your computer and use it in GitHub Desktop.
[Python] Array Slice
"""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