Python – Object Oriented Programming – Design Inheritance & Properties

Best Practices Designing for Inheritance and Polymorphism Polymorphism   Interface # Withdraw amount from each account in list_of_accounts def batch_withdraw(list_of_accounts, amount): for acct in list_of_accounts: acct.withdraw(amount) b, c, s = BankAccount(1000), CheckingAccount(2000), SavingsAccount(3000) batch_withdraw([b,c,s]) # uses bankaccount.withdraw, checking, Savings batch_withdraw() doesn’t need to check the object to know which withdraw() to call Liskov substitution principle […]

Python – Object Oriented Programming – Exceptions

Integration with Python Operator overloading : comparison Object equality class Customer: def __init__(self, name, balance): self.name, self.balance = name, balance cust1 = Customer(“John Fisher”, 2100) cust2 = Customer(“John Fisher”, 2100) cust1 == cust2 > False   Variables are references class Customer: def __init__(self, name, balance, id): self.name, self.balance = name, balance self.id = id cust1 […]

Python – Object Oriented Programming – Class Inheritance

Inheritance and Polymorphism Instance and Class Data Core Principles of OOP Inheritance Extending functionality of existing code Polymorphism Creating an unified interface Encapsulation Bundling of data and Methods Instance-level data class Employee: def __init__(self, name, salary): self.name = name self.salary = salary emp1 = Employee(“Theo Mill”, 50000) emp2 = Employee(“Martina Kosova”, 65000) name , salary […]

Python Basics – Boolean Operations

Boolean Operations Boolean logic consists of operations done between True and False values : and ( logical conjunction) or ( logical disjunction) not ( logical negation ) Object Evaluation Evaluates as False Constants : False and None Numeric zero : 0 and 0.0 Lengths of zero : “” and [] Evaluates as True everything else […]

Python Basics – Dictionary

Dictionaries Lists my_list = [‘a’,’b’,’c’,’d’] # index 0 1 2 3 my_list[0] > ‘a’ my_list.index[‘c’] > 2 Intro Keys Values —- —— Firm Code FRD Process Date 10/14/2019 CUSIP 13246879 Representation of a dictionary =  { ‘key-1’ : ‘value-1’ , ‘key-2’ : ‘value-2’ , ‘key-3’ : ‘value-3’ , ‘key-4’ : ‘value-4’  } Creation # Create […]