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; # variables must match # 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
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])
a[0] = 100
1
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-31-b9edf07586be> in <module>() 1 a = (1, 2, 3) 2 print(a[0]) ----> 3 a[0] = 100 TypeError: 'tuple' object does not support item assignment
print(a[0])
1
help(min)
Help on built-in function min in module builtins: min(...) min(iterable, *[, default=obj, key=func]) -> value min(arg1, arg2, *args, *[, key=func]) -> value With a single iterable argument, return its smallest item. The default keyword-only argument specifies an object to return if the provided iterable is empty. With two or more arguments, return the smallest argument.