Recall & Review
beginner
What Python module is commonly used for working with dates and times?
The
datetime module is commonly used to work with dates and times in Python.Click to reveal answer
beginner
How do you get the current date and time in Python?
Use
datetime.datetime.now() to get the current date and time.Click to reveal answer
beginner
What is the difference between
date and datetime in Python?date stores only the year, month, and day. datetime stores date and time (hours, minutes, seconds, microseconds).Click to reveal answer
intermediate
How can you format a date object as a string in Python?
Use the
strftime() method with format codes, like date.strftime('%Y-%m-%d').Click to reveal answer
intermediate
How do you calculate the difference between two dates in Python?
Subtract one
date or datetime object from another to get a timedelta object representing the difference.Click to reveal answer
Which method returns the current date and time in Python?
✗ Incorrect
datetime.datetime.now() returns the current date and time.What does the
strftime() method do?✗ Incorrect
strftime() formats a date or datetime object as a string.What type of object do you get when subtracting two datetime objects?
✗ Incorrect
Subtracting two datetime objects returns a
timedelta object.Which Python module provides the
timedelta class?✗ Incorrect
The
timedelta class is part of the datetime module.How do you get only the date part from a datetime object?
✗ Incorrect
The
.date() method extracts the date part from a datetime object.Explain how to get the current date and time, and how to format it as a string in Python.
Think about how to get now and then convert it to a readable string.
You got /3 concepts.
Describe how to find the number of days between two dates in Python.
Remember what happens when you subtract dates.
You got /3 concepts.