Introductie tot Python voor Finance
Adina Howe
Instructor
prices.sort()type(prices)list.method()list.sort() sorteert elementen oplopend
prices = [238.11, 237.81, 238.91]prices.sort()print(prices)
[237.81, 238.11, 238.91]
list.append() voegt één element toe aan een lijst
months = ['January', 'February', 'March']months.append('April')print(months)
['January', 'February', 'March', 'April']
list.extend() voegt elk element afzonderlijk toe
months.extend(['May', 'June', 'July'])print(months)
['January', 'February', 'March', 'April', 'May', 'June', 'July']
list.index(x) geeft de laagste index waar element x voorkomt
months = ['January', 'February', 'March']
prices = [238.11, 237.81, 238.91]
months.index('February')
1
print(prices[1])
237.81
min(list): geeft het kleinste element
max(list): geeft het grootste element
months = ['January', 'February', 'March']
prices = [238.11, 237.81, 238.91]
# Laagste prijs bepalen min_price = min(prices)# Index van laagste prijs min_index = prices.index(min_price)# Maand met laagste prijs min_month = months[min_index] print(min_month)
February
Introductie tot Python voor Finance