Instructions if

Python intermédiaire pour la finance

Kennedy Behrman

Data Engineer, Author, Founder

Afficher seulement les ventes

trns = { 'symbol': 'TSLA', 'type':'BUY', 'amount': 300}
print(trns['amount'])
300
Python intermédiaire pour la finance

Énoncés composés

énoncé de contrôle
   instruction 1
   instruction 2
   instruction 3
Python intermédiaire pour la finance

Énoncé de contrôle

if <expression> :
if x < y:
if x in y:
if x and y:
if x:
Python intermédiaire pour la finance

Blocs de code

if <expression>:
    statement
    statement
    statement
if <expression>: statement;statement;statement
Python intermédiaire pour la finance

Afficher seulement les ventes

trns = { 'symbol': 'TSLA', 'type':'BUY', 'amount': 300}
if trns['type'] == 'SELL':
    print(trns['amount'])
trns['type'] == 'SELL'
False
Python intermédiaire pour la finance

Afficher seulement les ventes.

trns = { 'symbol': 'APPL', 'type':'SELL', 'amount': 200}
if trns['type'] == 'SELL':
    print(trns['amount'])
200
Python intermédiaire pour la finance

Else

if x in y:
    print("I found x in y")
else:
    print("No x in y")
Python intermédiaire pour la finance

Elif

if x == y:
    print("equals")
elif x < y:
    print("less")
Python intermédiaire pour la finance

Elif

if x == y:
    print("equals")
elif x < y:
    print("less")
elif x > y:
    print("more")
elif x == 0
    print("zero")
Python intermédiaire pour la finance

Else avec elif

if x == y:
    print("equals")
elif x < y:
    print("less")
elif x > y:
    print("more")
elif x == 0
    print("zero")
else:
    print("None of the above")
Python intermédiaire pour la finance

Passons à la pratique !

Python intermédiaire pour la finance

Preparing Video For Download...