MulaiMulai sekarang secara gratis

Creating datetimes for dates

Imagine that as a financial analyst, you are trying to understand the history of market crashes. In order to represent crashes in your code, you want to represent the times that they occurred. Two significant market crashes are the Kennedy Slide, also known as the Flash Crash, which started May 28, 1962, and the Black Monday crash of October 19th, 1987.

Latihan ini adalah bagian dari kursus

Intermediate Python for Finance

Lihat Kursus

Petunjuk latihan

  • Create a datetime for the current time.
  • Create a datetime to represent the time of the Flash Crash.
  • Create a datetime to represent the time of the Black Monday Crash.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

import datetime

# Date and time now
now = datetime.datetime.____()
print(now)

# Flash crash May 28, 1962
flash_crash = datetime.datetime(____, 5, 28)
print(flash_crash)

# Black Monday Oct 19, 1987
black_monday = datetime.____(____, ____, ____)
print(black_monday)
Edit dan Jalankan Kode