Published on 1 Feb 2013
School
Department
Course
Professor

Nov. 19 Classes, Objects
Class – type of an object (data that they store)
Ie) str series of smaller strs
Object – instance of a class
Ie) list class but each instantiation can be edited/changed
Method- function belonging to an obj
-don’t relaly need exs) in docString
(not new!)
-ie) my_str = str(12.57) creat obj
-my_str.ljust(10) operate/change object
-my_str is an object of str class & method ljust
Creating Objects
Start with ClassName:
camelCase not pot_hole_case
o caps, no spaces/underscores
Built-in Methods:
must have __init__ (don’t expect user to ever call)
aka constructor method
defines code that runs when new obj of this type is created
setup default parameter
__str__
o Returns desired output when object of this class is cast to a str or printed
“self”:
Every method (built-in too) gets implicitly passed a copy of the obj itself
Don’t include in method call, method def’n
Allows objs to methods to access obj itself