CSC148H1 Lecture Notes - Lecture 19: Arity, Init
katrinasavvy and 38715 others unlocked
1
CSC148H1 Full Course Notes
Verified Note
1 document
Document Summary
References: code seen in the pictures can be found on the csc148 website: http://www. teach. cs. toronto. edu/~csc148h/winter. To differentiate between module function and method: Indentation: module level functions won"t have any indent before it, self attribute. When to choose module level function over a class level method: when behavior is closely associated with class, make it class level, your design decision. Last lecture, leaf_count, height, arity were implemented as module functions. Note how there is no indent: outside of class tree. Ex: tree implemented as method inside class tree. Indent before height because it is part of class tree. Notice how the code is very similar to the module functions: however, there is an indent. In addition, parameters are called different: c. height() instead of height(x) because it is part of a class, self. children. The same can be done for the other module functions we implemented last class. Self. value = value: copy children if not none, never have a mutable default parameter.