What is the output of the following code?

Python / Python Date

204

Program:

from datetime import date
first_date = date(2014, 7, 2)
last_date = date(2014, 7, 11)
n = last_date - first_date
print(n.days)

Output:

9

Explanation:

9 days

The code imports the date class from the datetime module. It then creates two date objects, first_date and last_date, which are set to July 2nd, 2014 and July 11th, 2014 respectively. The variable n is assigned the value of the difference between last_date and first_date, which is calculated using the subtraction operator. The program then prints the number of days between the two dates by accessing the days attribute of the timedelta object returned by the subtraction operation. The output will be 9 days.


This Particular section is dedicated to Programs only. If you want learn more about Python. Then you can visit below links to get more depth on this subject.