+3 votes
in Programming Languages by (60.5k 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 (256k 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')