year_born = ("Paris Hilton", 1981) # tuple packing
print(year_born)
('Paris Hilton', 1981)
star = "Paris", 'J', 'Hilton', 1981, 32, 1.2 # tuple packing
star
('Paris', 'J', 'Hilton', 1981, 32, 1.2)
type(star)
tuple
# tuple assignment
fname, mi, lname, year, age, income = star # tuple unpacking;
# no. of variables must match no. tuple values
fname
'Paris'
lname
'Hilton'
print(income)
1.2
# swap values of two variables
a = 100
b = 200
a, b = b, a
print(a, b)
200 100
name = ('John', 'A.', 'Smith')
print(name[0], name[1], name[2])
John A. Smith
len(name)
3
'John' in name
True
'B.' in name
False
'Jake' not in name
True
def maxAndMin(a, b, c, d, e):
myMax = a #max(a, b, c, d, e)
if myMax < b:
myMax = b
if myMax < c:
myMax = c
if myMax < d:
myMax = d
if myMax < e:
myMax = e
values = [a, b, c, d, e]
myMin = min(values)
return (myMax, myMin)
ab = maxAndMin(10, 20, 5, 100, 34)
print('max =', ab[0], 'min=', ab[1])
max = 100 min= 5
a = (1, 2, 3)
print(a[0])
1
a[0] = 100
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-6-b6d7a4db9a51> in <module>() ----> 1 a[0] = 100 TypeError: 'tuple' object does not support item assignment