If 语句

Python 金融进阶

Kennedy Behrman

Data Engineer, Author, Founder

仅打印卖出记录

trns = { 'symbol': 'TSLA', 'type':'BUY', 'amount': 300}
print(trns['amount'])
300
Python 金融进阶

复合语句

复合语句
   语句 1
   语句 2
   语句 3
Python 金融进阶

控制语句

if <expression> :
if x < y:
if x in y:
if x and y:
if x:
Python 金融进阶

代码块

if <expression>:
    statement
    statement
    statement
if <expression>: statement;statement;statement
Python 金融进阶

仅打印卖出记录

trns = { 'symbol': 'TSLA', 'type':'BUY', 'amount': 300}
if trns['type'] == 'SELL':
    print(trns['amount'])
trns['type'] == 'SELL'
False
Python 金融进阶

仅打印卖出记录。

trns = { 'symbol': 'APPL', 'type':'SELL', 'amount': 200}
if trns['type'] == 'SELL':
    print(trns['amount'])
200
Python 金融进阶

Else(否则)

if x in y:
    print("在 y 中找到 x")
else:
    print("y 中没有 x")
Python 金融进阶

Elif(否则如果)

if x == y:
    print("相等")
elif x < y:
    print("更小")
Python 金融进阶

Elif(否则如果)

if x == y:
    print("相等")
elif x < y:
    print("更小")
elif x > y:
    print("更大")
elif x == 0
    print("零")
Python 金融进阶

Elif 搭配 else

if x == y:
    print("相等")
elif x < y:
    print("更小")
elif x > y:
    print("更大")
elif x == 0
    print("零")
else:
    print("以上皆非")
Python 金融进阶

Ayo berlatih!

Python 金融进阶

Preparing Video For Download...