OOP: Structure, Encapsulation, Customization
1. Using Classes
class Person: def __init__(self, name, age, pay=0, job=None): self.name=name self.age=age self.pay=pay self.job=job if __name__==‘__main__‘: bob=Person(‘bob smith‘, 42, 30000, ‘software‘) sue=Person(‘sue jones‘,45, 45000,‘hareware‘) print(bob.name, sue.pay) print(bob.name.split()[-1]) sue.pay *= 1.1 print(sue.pay)
2. Adding Behavior