Saturday, November 23, 2013
Week Eleven
Saturday November 23, 2013.
TOPIC(s): [Attributes in Hiding]
This week the class took a turn into more complex features of Python's classes in terms of assigning the initialize attribute statements. Being a relative new programmer before I took the course, I found it understandable why programmers would change variable names in classes, for in order to ensure that the class would function in a certain way the programmer intended it to be. Giving a short example, a unique class of turning a matrix code of numbers into string of words would not particularly involve a float point value. With this topic, the use of exceptions that was introduced earlier in the course broadened, where it was used here in a much stricter environment compared to the traditional "if-else" statements and hierarchy in the "try-except" clauses.
With this topic, I learned various more "properties" and built-ins of Python, such as the property, which takes in methods of a class, and sets the properties of a instance variable name that it is assigned to. So instead of the user calling the methods of the class individually, property takes care of setting the attribute properties in one go, or that is how I thought this built-in takes it. The last interesting feature learned this week was that there are different versions of using recursion. Where instead of calling on the function name directly inside itself, in cases of arbitrary class methods such as __str__ and __eq__, the two items would be compared...
ex - return one == two
return str(one + two)
within the function body, and recursion is called in this manner.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment