Home Python Course Menu Book

Python Code Libraries


If you look at the Project area on the left of PyCharm, you'll see a category called External Libraries.

The External Libraries section of PyCharm

(If you can't see a Project area, from the menus at the top of PyCharm, click View. From the View menu, click Tool Windows > Project.)

You can import from these external libraries, if you like. As an example, expand External Libraries to see the following:

The PyCharm external libraries section expanded

Extend the one called Lib. Now scroll down and you'll see there are .py files called datetime and calendar:

The calendar and datetime Python modules

These are both files you can import into your projects, using the same techniques as outlined previously. Try it out. In your first file code, add import lines for datetime and calendar:

import datetime
import calendar

Now add the following code:

dateNow = datetime.date.today()

Try something from the calendar file with these lines:

isLeapYear = calendar.isleap(1970)
if isLeapYear: print("It's a leap year") else: print("It's not a leap year")

You could will look like this:

Python code using the datetime and calendar modules

When you run your program, the today part will print out something like:


For the year 1970, it will print out "Not a leap year". Try 1972, though, and see what prints out.

In the next lesson, we'll import a third-party library to use with images.