CS 162 Flashcards

1
Q

Where would an else block go in exception handling?

A

After the except block(s)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Under what conditions does the else block execute in exception handling?

A

Only if the code in the try block doesn’t cause any exceptions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What has mostly replaced the practice of using a finally block to release a resource the program is using (e.g., closing a file)?

A

The with statement - in re file handling

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Is the finally block required or optional?

A

Optional

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Syntax for inheritance (showing the is-a relationship)

A
class Duck(Bird):
as opposed to just:
class Duck:
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

constructor

A

The __init__() method in Python; used to instantiate an object. It initializes assigned values to the data members.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What do GUIs use inheritance for?

A

To create a hierarchy of windows, panes, dialog boxes, buttons, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

object composition

A

When one class contains an object of another class as one of its data members.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Syntax for super() in the init method

A
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Difference b/t return double and return double()

A

“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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

how to make a copy of a list

A

list_2 = list(list_1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly