安全访问与删除
Alphabet Inc. 于 2015 年在 Google 重组后成立。随着时间分析股价变化,是金融领域的常见任务。存储股票数据的一种方式是:在字典中将日期作为键,将价格作为值。
在本练习中,您需要在事先不确定某些日期是否有数据的情况下,访问 Alphabet 公司在不同日期的收盘价。提供的字典 alphabet_hist 使用 datetime 作为键、收盘价作为值。还提供了一个名为 closing_price_date 的 datetime 对象。
本练习是课程的一部分
Python 金融进阶
交互式实操练习
通过完成这段示例代码来试试这个练习。
# 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.____(____))