python person class

Solutions on MaxInterview for python person class by the best coders in the world

showing results for - "python person class"
Ismael
09 Sep 2020
1import datetime # we will use this for date objects
2
3class Person:
4
5    def __init__(self, name, surname, birthdate, address, telephone, email):
6        self.name = name
7        self.surname = surname
8        self.birthdate = birthdate
9
10        self.address = address
11        self.telephone = telephone
12        self.email = email
13
14    def age(self):
15        today = datetime.date.today()
16        age = today.year - self.birthdate.year
17
18        if today < datetime.date(today.year, self.birthdate.month, self.birthdate.day):
19            age -= 1
20
21        return age
22
23person = Person(
24    "Jane",
25    "Doe",
26    datetime.date(1992, 3, 12), # year, month, day
27    "No. 12 Short Street, Greenville",
28    "555 456 0987",
29    "jane.doe@example.com"
30)
31
32print(person.name)
33print(person.email)
34print(person.age())
35