Chap25. Coding Class Trees Flashcards

(11 cards)

1
Q

Each Class statement generates a new class object

A

##

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

Each time a class is called, it generates a new instance object.

A

##

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

Instances are automatically linked to the classes from which they are created.

A

##

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

Classes are linked to their superclasses by listing them in parentheses in a class header line; the left-to-right order

A

##

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

What is the main point of OOP in Python?

A

OOP is about code reuse – you factor code to minimize redundancy and program by customising what already exists instead of changing code in-place or starting from scratch.

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

Where does an inheritance search look for an attribute?

A

An inheritance search looks for an attribute first in the first instance object, then the class the instance it was created from, then in all higher superclasses. It progresses from bottom up, left to right. The lowest version of the attribute will always win.

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

What is the difference between a class object and an instance object?

A

Both class and instance objects are namespaces (packages of variables that appear as attributes). The main difference between them is that classes are like a factory for creating multiple instances. Classes also support operator overloading methods, which instance inherits, and treat any functions nested within them as special methods for processing instances.

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

Why is the first argument in a class method function special?

A

The first argument in a class method function is special because it always receives the instance object that is the implied subject of the method call. It’s usually called ‘self’ by convention.

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

What is the __init__ method used for?

A

If the __init__ method is coded or inherited in a class, Python calls it automatically each time an instance of that class is created. It’s known as the constructor method; it is passed the new instance implicitly, as well as any arguments passed explicitly to the class name. It’s also the most commonly used operator overloading method. If no __init__ method is present, instances simply begin life as empty namespaces.

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

How do you create a class instance?

A

You create a class instance by calling the class name as though it was a function; any arguments passed into the class name show up as arguments two and beyond in the __init__ constructor method.

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

How do you specify a class’ superclasses?

A

You specify a class’s superclasses by listing them in parentheses in the class statement, after the new class’s name. The left-to-right roder in which the classes are listed in the parentheses gives the left-to-right inheritance search order in the class tree.

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