Psst! Check what courses we have in our offer, and get them all here to save $727. Tick-tock—this deal ends on 3/21.
Introduction
Time
3. Time object: internal elements
Date
Datetime
Summary

Instruction

Good job! Internally, time objects consist of four elements: hour, minute, second, and microsecond. To get a specific element, you can use the following syntax:

fra_mad_scheduled = datetime.time(9, 30, 0)

print('Hour:', fra_mad_scheduled.hour)
print('Minute:', fra_mad_scheduled.minute)
print('Second:', fra_mad_scheduled.second)
print('Microsecond:', fra_mad_scheduled.microsecond)

As you can see, we used the dot operator (.) to get the specific hour, minute, second, or microsecond element.

Exercise

Modify the template from the previous exercise so that it formats time in the following way:

Typical work start time is 8.45

Note that we expect the hour and minutes to be separated with a dot (.), and not a colon (:), which is the default time format.

Note: from now on, we will be importing the datetime module for you. 🙂

Stuck? Here's a hint!

You'll have to extract the hour and minute elements separately and add a dot between them.