CS 61A Extra Lecture 6 - University of California, Berkeley
Announcements
Objects in Python
Implementing an Object System
Example: Account
Implementing Inheritance
Objects in Python
CS 61A Extra Lecture 6
Implementing an Object System
Brian Hou
March 5, 2015
Announcements
Objects in Python
Implementing an Object System
Example: Account
Implementing Inheritance
Objects in Python
Announcements
? Extra Homework 2 due tonight! ? Extra Homework 3 due Thursday 4/2
Announcements
Objects in Python
Implementing an Object System
Example: Account
Implementing Inheritance
Objects in Python
Objects in Python
Announcements
Objects in Python
Implementing an Object System
Example: Account
Implementing Inheritance
Objects in Python
Review: Classes and Methods
class Adder: def __init__(self, a, b): self.a, self.b = a, b def total(self): return self.a + self.b
>>> seven = Adder(6, 1) >>> seven.total >>> seven.total() 7 >>> Adder.total(seven) 7
Announcements
Objects in Python
Implementing an Object System
Example: Account
Implementing Inheritance
Objects in Python
Accessing Attributes
When we use object-oriented programming, there are two fundamental operations: ? looking up an attribute's value ? defining an attribute's value
We can use the getattr and setattr functions >>> getattr(seven, 'a') # seven.a 6 >>> setattr(seven, 'a', 7) # seven.a = 7 >>> getattr(seven, 'total')() 8
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related searches
- university of california essay prompts
- university of california supplemental essays
- university of california free tuition
- university of california campuses
- university of california online certificates
- address university of california irvine
- university of california at irvine ca
- university of california irvine related people
- university of california irvine staff
- university of california berkeley majors
- university of california berkeley cost
- university of california berkeley information