Week 4 was a quiet week, I suppose. On Monday, we simply took a look at our first assignment, which I've started already (done 70% but need a little help for the last bit). Also, we took a look at the nested list recursion problem.
On Wednesday, we went into detail about a "tree burst" recursion function. What this function did was that it created a tree-like drawing when running it. Obviously, this example was to further reinforce our understanding on recursion and the different ways it can be written.
The lab this week was also pretty informative. In addition to working on more Object Oriented Programming, we also worked on UnitTest, which was something that we never really went into in csc108.
All in all, it was a pretty dry week. I should probably look more into the properties function and learn how to fully implement it.
Thursday, January 30, 2014
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
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()
Saturday, January 18, 2014
Week 2
Week two was much better, in my opinion, as we started to focus on actual content. While much of the content were things that are still retained in my mind from last semester's csc108, there were a few things that caught my attention that were either new or different.
One thing that I noticed was that the way our professor likes to write type contracts is to do it in the parameters itself, using a colon to designate a type.
ex: >>> def apple(colour : str) -> str:
ex: >>> def apple(colour : str) -> str:
I should quickly get used to this, because apparently that's what he wants us to do.
Another thing that particularly interested me was the usage of the property function in classes. It's something that prevents instances from changing, to make the initialized objects harder to modify. I'm still not quite sure how it works, but I plan on either going to a help session or going to the teacher to clarify this.
Finally, we learned recursion. So far, the examples are pretty basic. I'm sure the difficulty will ramp up soon enough, but luckily so far it's okay. Simply put, it's a function that calls itself.
P.S. the lab was okay. I felt that the instructions were not really clear, but maybe that's just me.
P.P.S list comprehensions were made more clear, set() function was shown, ternary if's shown.
list comprehension:
S = [x**2 for x in range(10)]
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
Set()
Ternary if:
'true' if True else 'false'
P.P.S list comprehensions were made more clear, set() function was shown, ternary if's shown.
list comprehension:
S = [x**2 for x in range(10)]
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
Set()
Ternary if:
'true' if True else 'false'
Subscribe to:
Posts (Atom)