if 文

Intermediate Python for Finance

Kennedy Behrman

Data Engineer, Author, Founder

売りのみを出力

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

複合文(Compound statements)

複合文
   文 1
   文 2
   文 3
Intermediate Python for Finance

制御文(if)

if <expression> :
if x < y:
if x in y:
if x and y:
if x:
Intermediate Python for Finance

コードブロック

if <expression>:
    statement
    statement
    statement
if <expression>: statement;statement;statement
Intermediate Python for Finance

売りのみを出力

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

売りのみを出力

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

else

if x in y:
    print("I found x in y")
else:
    print("No x in y")
Intermediate Python for Finance

elif

if x == y:
    print("equals")
elif x < y:
    print("less")
Intermediate Python for Finance

elif

if x == y:
    print("equals")
elif x < y:
    print("less")
elif x > y:
    print("more")
elif x == 0
    print("zero")
Intermediate Python for Finance

elif と else

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")
Intermediate Python for Finance

練習しましょう!

Intermediate Python for Finance

Preparing Video For Download...