Sunday, January 26, 2014

Week 3

This week, we focused on what we call Object Oriented Programming. Essentially, from what I can understand, it basically means a focus on classes. The use of  "class" is to be able to focus the programming around an "object", hence, OOP. When creating the class, we can add methods to indicate the class(object) to do something. For example, creating a 'toy' class and then a 'play' method. In addition to creating new classes, we can also create a subclass (extended class) of a superclass (base class), which inherits all of the superclass' methods. Note, however, that the superclass' methods can still be modified in the extended class if you write the method in the superclass (check IntStack for example).

Exceptions were also made more clear this week, and the creation of new Exceptions by sub-classing the Exception class was also explained.

Other things learned this week:

Try: This function tests the following lines of code. If it reaches an exception it looks for an except statement further below that matches the exception, and then proceeds accordingly.

print Exception('string') prints the string

Class variables are variables that exist in class and are universal with all methods. This is where the property function comes in play

To reverse a list, [ : : -1] is used

__repr__ is used when representing a class. This means that when you type something like

>>> toy = Toy()

and then you type toy in the python shell like this,

>>> toy

you get something other than the default return
ex:
>>> Toy()

No comments:

Post a Comment