Classes & OOP Flashcards

1
Q

Whats the difference of ‘==’ operator and is ‘?

A

’=’ checks if the objects are the same from a value perspective.
On the other hand, the is operator check if they point to the same memory location

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

Which are the benefits of defining a custom exception classtype?

A

a) code maintanable

b) error cases to stand out

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

What assigning does in python?

A

Assigning in python only binds names to an object. For immutable objects, that does not make any difference.

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

How shallow copy takes place in mutable objects like lists,dictionaries and sets?

A

It is happened by calling its factory functions.

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

What is a shallow copy?

A

It is the process of constructing a new collection of objects but then keeping the references to the children objects found on the original. It is an one level only clone.

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

What is deep copy?

A
It is the process where a collection of objects is generated and then for each object a new copy of the original object is made. So, with this procedure, the whole object tree is traversed.
We’re going to create a deep copy using the deepcopy() function defined in the copy module instead
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

For what abstract base classes are good for?

A
They are good for because it ensure that every subclass will implement all the methods of the base class.
Particularly for implementation we use ABC which reassures
a) a subclass wont be instantiated until all the base class methods are defined
b) base class cannot be instantiated
from abc import ABCMeta, abstractmethod 
class Base( metaclass = ABCMeta)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly