+2 votes
in Programming Languages by (7.6k 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

0 votes
by (14.8k points)

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
 

...