Created
February 23, 2018 23:21
-
-
Save sravi4701/802804249673d1af0cf5c0e7f0447295 to your computer and use it in GitHub Desktop.
Unpacking a sequence into separate variables
This file contains 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
# comma_separated_variables = sequence | |
# given a data in the form of list | |
data = ['Ravi', 21, (1996, 12, 5)] | |
# extract name, age, dob from data | |
name, age, dob = data | |
print(name) # Ravi | |
print(age) # 21 | |
print(dob) # (1996, 12, 5) | |
# It works with any sequence eg. | |
s = 'hello' | |
a, b, _, c, d = s | |
print(b) # e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment