CSCA08H3 Lecture Notes - Init, Camel Case

20 views1 pages
Published on 1 Feb 2013
School
Course
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
Unlock document

This preview shows half of the first page of the document.
Unlock all 1 pages and 3 million more documents.

Already have an account? Log in

Get OneClass Notes+

Unlimited access to class notes and textbook notes.

YearlyBest Value
75% OFF
$8 USD/m
Monthly
$30 USD/m
You will be charged $96 USD upfront and auto renewed at the end of each cycle. You may cancel anytime under Payment Settings. For more information, see our Terms and Privacy.
Payments are encrypted using 256-bit SSL. Powered by Stripe.