Function
def f(x):
no return will return None
Tuples元組
- an ordered sequence of elements, can mix element types
- immutable
t = (2, "mit", 3)
t[1] = 4 error
conveniently used to swap variable values: (x, y) = (y, x)
def f(x, y)
a = x // y //integer division
b = x % y
return (a , b)
List
- lists are mutable
L = [2, 'a', 4, [1,2]]
len(L)=4
total = 0
for i in L:
total +=i
print total
add elements: L.append(element)
convert string to list: list(s)
s.split('<')
''.join(L) to turn a list of characters into a string
- sort() and sorted()
sorted does not mutate
sort mutate, return nothing
colone a list: chill = cool[:]