CS 162 Flashcards
Where would an else block go in exception handling?
After the except block(s)
Under what conditions does the else block execute in exception handling?
Only if the code in the try block doesn’t cause any exceptions
What has mostly replaced the practice of using a finally block to release a resource the program is using (e.g., closing a file)?
The with statement - in re file handling
Is the finally block required or optional?
Optional
Syntax for inheritance (showing the is-a relationship)
class Duck(Bird): as opposed to just: class Duck:
constructor
The __init__() method in Python; used to instantiate an object. It initializes assigned values to the data members.
What do GUIs use inheritance for?
To create a hierarchy of windows, panes, dialog boxes, buttons, etc.
object composition
When one class contains an object of another class as one of its data members.
Syntax for super() in the init method
For a child class inheriting 2 of 3 arguments from super: def \_\_init\_\_(self, library_item_id, title, author): super().\_\_init\_\_(library_item_id, title) self._author = author
Difference b/t return double and return double()
“return double” returns the actual function; “return double()” returns the output of the function call (though you would prob need arguments). Remember that functions are first-class objects and can be returned!
how to make a copy of a list
list_2 = list(list_1)