Editor

Use Import Aliases

Beginner · Write the code · from Python Imports: How import Really Works (Modules, Packages, Paths)

From the lesson: Python Imports: How import Really Works (Modules, Packages, Paths)

Think of a library. Instead of buying every book in the world and keeping them in your house, you go to the library and check out only the books you need. When you're done, you return them.

Read the lesson

Import the datetime module with the alias dt. Then:

1. Create a date object for January 15, 2025 using dt.date(2025, 1, 15) and store it in my_date

2. Print the date using print(my_date)

3. Print the year using print(my_date.year)

4. Print the weekday name using print(my_date.strftime('%A'))

# Import datetime with an alias

More Imports exercises

All Python exercises · 50 practice problems · Modules & Packaging quiz