BaşlayınÜcretsiz Başlayın

Accessing datetime attributes

Suppose you are analyzing the tech bubble crash of 2000. For the sake of reporting, you need to assign the year, month, and day values to variables.

Use the attributes of a datetime object to assign the correct values to these variables.

Bu egzersiz

Intermediate Python for Finance

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Assign the year of the crash to the variable yr.
  • Assign the month of the crash to the variable mth.
  • Assign the day of the crash to the variable day.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# 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}")
Kodu Düzenle ve Çalıştır