Week 5 Flashcards

1
Q

What is __str__ and what does it do?

A

It is the string magic method.
It returns a human readable string representation of the object.

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

What is __repr__ and what does it do?

A

It is a magic method for the representation of how to recreate the object.
It returns an unambiguous representation of the object.

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

What does the __add__ method do?

A

It defines the behavior for the + operator between two objects

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

What is __dir__ and what does it do?

A

It is the directory magic method
It returns a list of the valid attributes and methods for the object

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

What is __bool__ and what does it do?

A

It is the boolean magic method
It returns the defined boolean value for the object

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

What is __init__ and what does it do?

A

It is the constructor magic method and it defines the attributed within the object.

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

What is the __len__ magic method?

A

It defines the length for the given object

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

How do you define a subclass?

A

class Sub_class(Base_class):

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

When do you raise exceptions?

A

If you don’t have control over input

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

When do you use assertions?

A

Whenever code is checking input or conditions you have control over

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

How do you gather info on an unknown exception?

A

except Exception as e:
Optional: print(e)

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

How do you use the super() method in __init__?

A

def __init__(self, name):
super().__init__(name)

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

What is a polymorphic function?

A

A function that applies to many (ploy) forms (morph) of data

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

What is a generic function?

A

A function that can apply to arguments of different types

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

What is type dispatching?

A

It allows you to change what the function does based on the type of input

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

What is inheritance?

A
17
Q

What does isinstance() do?

A
18
Q

What is composition?

A
19
Q

What are the two other names for base class?

A
  1. Superclass
  2. Parent class
20
Q

What is modularity?

A

Breaking a project down into smaller more manageable bits called modules that can be reused in different parts of the program.

21
Q

What is modular design?

A

A design principle that breaks down a system into smaller, more manageable parts, called modules that can be independently created, modified, and reused.

22
Q

What is an interface in classes?

A