+3 votes
in Programming Languages by (73.8k points)
I can write a small code to find the age of a person in years, but what is the pythonic way to find the age?

1 Answer

+1 vote
by (349k points)
selected by
 
Best answer

You can use date function of datetime library. Here is an example:

Let's say mm-dd-yyyy is the date of birth of the person.

from datetime import date
age = date.today().year - int(yyyy)

E.g.

>>> date.today().year - int('1981')
37
 


...