Corey Schafer, Object-Oriented Programming 6 parts
Setting up a Python Development Environment
Requirements: syntax highlighting, beautification, linter, IntelliSense: list members, parameter info, quick info, autocompletion,
Why? Logically group our data and functions that we can easily reuse or build upon
Terminology
Attributes and methods - functions that is associated with class
A class is a blueprint for creating instances
class Employee:pass# instances of a Employee classesemp_1 = Employee()emp_2 = Employee()s# unique data#manually variable setting - prone to human erroremp_1.first = 'Corey'emp_1.last = 'Scafer'emp_1.email = '[email protected]'emp_1.pay = '50000'emp_2.first = 'Test'emp_2.last = 'User'emp_2.email = '[email protected]'emp_21.pay = '60000'######class Employee:def __init__(self,first,last,pay):#set instance variableself.first = firstself.last = lastself.pay =payself.email = first +'.' + last + '@company.com'# each method within a class automatically takes the insance as the first argument# and we always call that selfdef fullname(self)return '{}{}'.format(self.first,self.last)# better solution: runs init automaticallyemp_1 = Employee('Corey','Scafer',50000)emp_2 = Employee('Test','User',60000)print(emp_1.email)print(emp_2.email)# running actions#manuallyprint('{}{}'.format)emp_1.first,emp_1,last))# betterprint(emp_1.fullname()) # notice the parenthesis as it is a method#notes#classes are kinda like function# remember to put self in methods in classemp_1.fullname() is same as Employee.fullname(emp_1))