Vaggelis Manousakis
Vaggelis Manousakis

Reputation: 391

How to find out how many days a month has and save it in a variable

I have been struggling lately to find out how many days a month has and save them in a var.So far my progress is:

import calendar

days_of_month = calendar.monthrange(2018,2)

However this brings up (3,28).I only want the number 28.What can i do to save only 28 in a var ?

Upvotes: 0

Views: 87

Answers (1)

llllllllll
llllllllll

Reputation: 16404

(3, 28) is a tuple, to get the second value, you just need index:

days_of_month = calendar.monthrange(2018,2)[1]

Note that index starts from 0, thus second index is 1.

Upvotes: 1

Related Questions