-
-
Save H3lllfir3/2f04ebf284a26efe5e3328925d4a6390 to your computer and use it in GitHub Desktop.
Sequence Unpacking
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
| >>> 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