Classes & OOP Flashcards
Whats the difference of ‘==’ operator and is ‘?
’=’ 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
Which are the benefits of defining a custom exception classtype?
a) code maintanable
b) error cases to stand out
What assigning does in python?
Assigning in python only binds names to an object. For immutable objects, that does not make any difference.
How shallow copy takes place in mutable objects like lists,dictionaries and sets?
It is happened by calling its factory functions.
What is a shallow copy?
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.
What is deep copy?
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
For what abstract base classes are good for?
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)