安全存取與刪除
Alphabet Inc. 於 2015 年因 Google 的公司重組而成立。隨時間分析股價變化是金融領域的常見任務。儲存股價資料的一種方式,是在字典中使用日期作為鍵、價格作為值。
在這個練習中,你要在事先不確定各日期是否有資料的情況下,存取 Alphabet 不同日期的收盤價。提供的字典 alphabet_hist 以 datetime 作為鍵、以收盤價作為值。已提供名為 closing_price_date 的 datetime 物件。
本練習屬於課程
Intermediate Python for Finance
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Closing price for day before
day_before_closing_price_date = closing_price_date - timedelta(days=1)
# Safely print closing price day before or None if it's missing
print(alphabet_hist.____(____))