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


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