What does importing a library do?

Question

What does importing a library do?

Answer

When you write programs of any significant size, you will put other people’s code to use. That’s all a library/module is - someone else’s code. Their code’s functionality is made available through these libraries after being imported and makes development lightyears easier by saving time and energy. Libraries save us from having to reinvent the wheel.
In this case, we’re importing the datetime library, which allows us to d all kinds of cool stuff! Here is the full documentation for the library, where you can find what all you can do with the library.
It’s a good idea to Google the documentation for any library you want to use from now on, as that’s a large part of being a developer!

23 Likes

5 posts were split to a new topic: How can i get my local time with python?

I would like to display the quarter (03 months) of a year, is it possible via the datetime library using the for loop?

Looks like a good explanation here https://stackoverflow.com/questions/1406131/is-there-a-python-function-to-determine-which-quarter-of-the-year-a-date-is-in

from datetime import datetime
from math import ceil
now = datetime.now()
month = now.month
quarter = ceil(month * 1/3)
print (month, quarter)    # 6 2
2 Likes