23
loading...
This website collects cookies to deliver better user experience
mySequence = [ 'FBA' , 20, 3000.30, (18, 12, 2000) ]
a, b, c, d = mySequence
print(a)
print(b)
print(c)
print(d)
mySequence = [ 'FBA' , 20, 3000.30, (18, 12, 2000) ]
a, b, c, d = mySequence
print(a)
print(b)
print(c)
print(d)
FBA
20
3000.3
(18, 12, 2000)
mySequence = [ 'FBA' , 20, 3000.30, (18, 12, 2000) ]
name, age, salary, dateOfBirth = mySequence
print(name)
print(age)
print(salary)
print(dateOfBirth)
FBA
20
3000.3
(18, 12, 2000)
dateOfBirth
variable as well by unpacking the variable.mySequence = [ 'FBA' , 20, 3000.30, (18, 12, 2000) ]
name, age, salary, (day, month, year) = mySequence
print(name)
print(age)
print(salary)
print(day)
print(month)
print(year)
FBA
20
3000.3
18
12
2000
myString = 'United'
p, q, r, s, t, u = myString
print(r)
#Output: i
x = (1, 2, 3)
p, q = x
Traceback (most recent call last):
File "/home/fba/Desktop/Practice/1.py", line 2, in <module>
p, q = x
ValueError: too many values to unpack (expected 2)
myString = ['FBA' , 'IJK' , 90, 11]
_, a, b, _ = myString
_
variable as a throwaway variable. Remember, if you use the same throwable variable more than one time, then if you want to print that throwable variable later, you will get the latest value you have assigned to the variable earlier in the output. Like, in the code given above, we have used _
variable both for the data FBA
and the data 11
. If you want to print the value of _
variable, then we will get 11
as the output as the latest value we have assigned to the _
variable was 11
.myString = ['FBA' , 'IJK' , 90, 11]
_, a, b, _ = myString
print(_)
11