Get startedGet started for free

Importing from a module

Another useful module is datetime, which allows you to create and work with dates and times, as well as time zones and time periods!

The datetime module has a function called date.

In this exercise, you'll practice importing and using the date method from the datetime module and use it to create a variable.

This exercise is part of the course

Intermediate Python for Developers

View Course

Exercise instructions

  • Import the date function from the datetime module.
  • Create a variable called deadline, assigning a call of date(), passing in the numbers 2024, 1, and 19, in that order, separated by commas.
  • Check the data type of deadline.
  • Print the deadline variable.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Import date from the datetime module
____ ____ ____ ____

# Create a variable called deadline
deadline = ____(____, ____, ____)

# Check the data type
print(____(____))

# Print the deadline
print(____)
Edit and Run Code