If-statements

Python voor Finance - gevorderd

Kennedy Behrman

Data Engineer, Author, Founder

Alleen verkopen printen

trns = { 'symbol': 'TSLA', 'type':'BUY', 'amount': 300}
print(trns['amount'])
300
Python voor Finance - gevorderd

Samengestelde statements

control statement
   statement 1
   statement 2
   statement 3
Python voor Finance - gevorderd

Controlestatement

if <expression> :
if x < y:
if x in y:
if x and y:
if x:
Python voor Finance - gevorderd

Codeblokken

if <expression>:
    statement
    statement
    statement
if <expression>: statement;statement;statement
Python voor Finance - gevorderd

Alleen verkopen printen

trns = { 'symbol': 'TSLA', 'type':'BUY', 'amount': 300}
if trns['type'] == 'SELL':
    print(trns['amount'])
trns['type'] == 'SELL'
False
Python voor Finance - gevorderd

Alleen verkopen printen.

trns = { 'symbol': 'APPL', 'type':'SELL', 'amount': 200}
if trns['type'] == 'SELL':
    print(trns['amount'])
200
Python voor Finance - gevorderd

Else

if x in y:
    print("I found x in y")
else:
    print("No x in y")
Python voor Finance - gevorderd

Elif

if x == y:
    print("equals")
elif x < y:
    print("less")
Python voor Finance - gevorderd

Elif

if x == y:
    print("equals")
elif x < y:
    print("less")
elif x > y:
    print("more")
elif x == 0
    print("zero")
Python voor Finance - gevorderd

Else met 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 voor Finance - gevorderd

Laten we oefenen!

Python voor Finance - gevorderd

Preparing Video For Download...