访问 datetime 的属性
假设您正在分析 2000 年的科技泡沫崩盘。为了撰写报告,您需要把年、月、日的数值分别赋给变量。
请使用 datetime 对象的属性,将正确的数值赋给这些变量。
本练习是课程的一部分
Python 金融进阶
练习说明
- 将崩盘发生的年份赋给变量
yr。 - 将崩盘发生的月份赋给变量
mth。 - 将崩盘发生的日期赋给变量
day。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# March 10, 2000 Tech Bubble Crash
tech_bubble = datetime(2000, 3, 10)
# Access the year
yr = tech_bubble.____
# Access the month
mth = tech_bubble.____
# Access the day
day = tech_bubble.____
print(f"Year: {yr}, Month: {mth}, Day: {day}")