import sys
sys.version
'3.10.6 | packaged by conda-forge | (main, Aug 22 2022, 20:41:22) [Clang 13.0.1 ]'
import sys
sys.version
'3.10.6 | packaged by conda-forge | (main, Aug 22 2022, 20:41:22) [Clang 13.0.1 ]'
class Person:
def __init__(self, FirstName, LastName, DOB, Height, Weight):
self.FirstName = FirstName
self.LastName = LastName
self.DOB = DOB
self.Height = Height
self.Weight = Weight
= Person("Julia", "Lang", (2012, 2, 12), 1.73, 51)
p p
<__main__.Person at 0x106880430>
type(p)
__main__.Person
type(p.DOB)
tuple
Let’s add a method that calculates a person’s age in years today by substracting today’s date from their birthdate:
class Person:
def __init__(self, FirstName, LastName, DOB, Height, Weight):
self.FirstName = FirstName
self.LastName = LastName
self.DOB = DOB
self.Height = Height
self.Weight = Weight
def getAge(self):
from datetime import datetime
return (datetime.now() - datetime(*self.DOB)).days/365
= Person("Julia", "Lang", (2012, 2, 12), 1.73, 51) p
p.getAge()
10.704109589041096