Instrukcje warunkowe

Python dla finansów – poziom średniozaawansowany

Kennedy Behrman

Data Engineer, Author, Founder

Wyświetlanie tylko sprzedaży

trns = { 'symbol': 'TSLA', 'type':'BUY', 'amount': 300}
print(trns['amount'])
300
Python dla finansów – poziom średniozaawansowany

Instrukcje złożone

control statement
   statement 1
   statement 2
   statement 3
Python dla finansów – poziom średniozaawansowany

Instrukcja sterująca

if <expression> :
if x < y:
if x in y:
if x and y:
if x:
Python dla finansów – poziom średniozaawansowany

Bloki kodu

if <expression>:
    statement
    statement
    statement
if <expression>: statement;statement;statement
Python dla finansów – poziom średniozaawansowany

Wyświetlanie tylko sprzedaży

trns = { 'symbol': 'TSLA', 'type':'BUY', 'amount': 300}
if trns['type'] == 'SELL':
    print(trns['amount'])
trns['type'] == 'SELL'
False
Python dla finansów – poziom średniozaawansowany

Wyświetlanie tylko sprzedaży.

trns = { 'symbol': 'APPL', 'type':'SELL', 'amount': 200}
if trns['type'] == 'SELL':
    print(trns['amount'])
200
Python dla finansów – poziom średniozaawansowany

Else

if x in y:
    print("I found x in y")
else:
    print("No x in y")
Python dla finansów – poziom średniozaawansowany

Elif

if x == y:
    print("equals")
elif x < y:
    print("less")
Python dla finansów – poziom średniozaawansowany

Elif

if x == y:
    print("equals")
elif x < y:
    print("less")
elif x > y:
    print("more")
elif x == 0
    print("zero")
Python dla finansów – poziom średniozaawansowany

Else z 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 dla finansów – poziom średniozaawansowany

Czas na ćwiczenia!

Python dla finansów – poziom średniozaawansowany

Preparing Video For Download...