Skip to content

Instantly share code, notes, and snippets.

@H3lllfir3
Last active August 21, 2020 15:59
Show Gist options
  • Select an option

  • Save H3lllfir3/2f04ebf284a26efe5e3328925d4a6390 to your computer and use it in GitHub Desktop.

Select an option

Save H3lllfir3/2f04ebf284a26efe5e3328925d4a6390 to your computer and use it in GitHub Desktop.
Sequence Unpacking
>>> nums = [10, 20, 30]
>>> a, b, c = nums
>>> a
10
>>> c
30
>>> student_tuple = ('Ayoub', [98, 85, 87])
>>> first_name, grades = student_tuple
>>> first_name
'Ayoub'
>>> name, *nums = ['Hamed', 1, 2, 3, 4, 5]
>>> name
'Hamed'
>>> nums
[1, 2, 3, 4, 5]
>>> head, *middle, tail = ['Mersad', 1, 2, 3, 4, 5, 'Reza']
>>> head
'Mersad'
>>> tail
'Reza'
>>> middle
[1, 2, 3, 4, 5]
>>> student_grades = [['Mamad', 1, 2, 3,], ['Hamed', 4, 5, 6], ['Mersad', 7, 8, 9]]
>>> for name, *grade in student_grades:
... print(grade)
...
[1, 2, 3]
[4, 5, 6]
[7, 8, 9]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment