Listes en Python

Introduction à Python pour la finance

Adina Howe

Instructor

Listes - crochets [ ]

months = ['January', 'February', 'March', 'April', 'May', 'June']
Introduction à Python pour la finance

Python utilise un indexage à zéro

list_figure

Introduction à Python pour la finance

Listes de sous-ensembles

months = ['January', 'February', 'March', 'April', 'May', 'June']
months[0]
'January'
months[2]
'March'
Introduction à Python pour la finance

Indexation négative des listes

months = ['January', 'February', 'March', 'April', 'May', 'June']
months[-1]
'June'
months[-2]
'May'
Introduction à Python pour la finance

Sous-ensemble d’éléments de liste avec découpage

Syntaxe de découpage

# Includes the start and up to (but not including) the end
mylist[startAt:endBefore] 

Exemple

months = ['January', 'February', 'March', 'April', 'May', 'June']
months[2:5]
['March', 'April', 'May']
months[-4:-1]
['March', 'April', 'May']
Introduction à Python pour la finance

Découpage étendu avec des listes

months = ['January', 'February', 'March', 'April', 'May', 'June']
months[3:]
['April', 'May', 'June']
months[:3]
['January', 'February', 'March']
Introduction à Python pour la finance

Découpe par étapes

# Includes the start and up to (but not including) the end
mylist[startAt:endBefore:step] 
months = ['January', 'February', 'March', 'April', 'May', 'June']
months[0:6:2]
['January', 'March', 'May']
months[0:6:3]
['January', 'April']
Introduction à Python pour la finance

Passons à la pratique !

Introduction à Python pour la finance

Preparing Video For Download...