-
👉Which sentence describing an abstract class is true?
- it provides a means for API
- it is a contract between two classes
- it is a class decorated with the
@abc.abstractclass
decorator - it is a class inheriting from the
Abstractclass
class
🗝️ Ans. i
-
👉Take a look at the snippet and choose one of the following statements which is true:
import abc @abc.abstractclass class BluePrint(abc.ABC): @abc.abstractmethod def hello(self): pass class WhitePool(BluePrint): def hello(self): print('Welcome to the White Pool!') wp = WhitePool()
- it is erroneous as there is a typo in the abstract method decorator.
- it defines one abstract class with one abstract method.
- it prints “Welcome to the White Pool”
- it is erroneous as there is no abc
abstractclass
decorator
🗝️ Ans. iii
-
👉 Select the correct answer. The chaining concept introduces the following attribute on exception instances:
__traceback__
, which is inherent only for implicitly chained exceptions__context__
, which is inherent for implicitly chained exceptions__traceback__
, which is inherent only for explicitly chained exceptions__cause__
, which is inherent for implicitly chained exceptions
🗝️ Ans. ii
-
👉The following snippet is an example of what kind of exception chaining?
Select the best answer:
class OwnMath(Exception): pass def calculatevalue(numerator, denominator): try: value = numerator / denominator except ZeroDivisionError as e: raise OwnMath from e return value calculatevalue(4, 0)
- explicitly chained exceptions
- implicitly chained exceptions
- the code is erroneous.
- the code is fine, and the script execution is not interrupted by any exception.
🗝️ Ans. i
-
👉 @property is used to decorate:
- a 'getter' type method
- any proxying method.
- a 'delete type method.
- a 'setter' type method
- an 'access controller' type method
🗝️ Ans. ii
-
👉What should he the order of decorators, placed in your code, controlling access to one specific attribute?
- first is @property then @attribute.getter or @attribute.setter
- first is @property then @attribute.setter or @attribute.deleter
- first is @attribute.getter, then @property or @attribute.setter
- first is @attribute.setter, then @property or @attribute.deleter
🗝️ Ans. ii
-
👉Look at the following code and name its elements.
class A: def init(self): self.name = None def function(self, value): self.b = value a = A()
- A is a class, function is a method, a is a method.
- A is a class, function is an object, a is an object.
- A is an attribute, function is a method, a is a method.
- A is a method, b is a method, a is a method.
🗝️ Ans. ii
-
👉What is the difference between inheritance and composition? Choose the best answer.
- both terms describe the same concept
- inheritance models an 'is a' relation whereas composition models a 'has a' relation.
- you cannot implement a multiple inheritance while multiple composition is possible.
- composition models an 'is a' relation whereas inheritance models a 'has a' relation.
🗝️ Ans. i
-
👉The function
id()
returns:- the identity of the object, a unique value amongst other objects
- the absolute memory address occupied by the object.
- a sequential number of the object created from the moment a Python script was started.
- the identity of the object representing the object type
🗝️ Ans. ii
-
👉Select the true statement about class methods:
- class methods are methods that work on the class itself and require class object instances.
- class methods are methods that work on the class itself.
- class methods are methods that work on the class objects that are instantiated.
- class methods cannot change class variables' values as there is no reference for the class.
🗝️ Ans. ii
-
👉What are class methods?
- class methods are classes that expect two parameters: one indicating the class object and other indicating the class itself.
- class methods are tool methods available to all class instances.
- class methods are classes that are bound to class instances.
- class methods are decorated with the @method trait.
🗝️ Ans. ii
-
👉Select the true sentence.
- *args refers to a tuple of all not explicitly expected arguments; **kwargs refers to a dictionary of all not explicitly expected keyword arguments
- *args refers to a list of all not explicitly expected arguments; **kwargs refers to a dictionary of all not explicitly expected keyword arguments
- **args refers to a tuple of all not explicitly expected arguments; *kwargs refers to a dictionary of all not explicitly expected keyword arguments
- *args collects all matched positional arguments; **kwargs collects all matched keyword arguments
🗝️ Ans. i
-
👉What is a decorator? Select the best answer.
- it can be only a function that wraps another function to perform additional steps.
- it is an only way to make your function safe by enforcing security checks for arguments values.
- it can be a function or class that only accelerates another function execution.
- it can be a function that returns a function that can be called later.
🗝️ Ans. iii
-
👉Which function can be used to get a list of methods inherent to an object?
__dict__()
__help__()
help()
dict()
🗝️ Ans. iii
-
👉What is the following special method responsible for?
Instancecheck(self, object)
- it is responsible for handling the
issubclass()
function calls. - it is responsible for handling the
instancecheck()
function calls - it is responsible for handling the is
instance()
function calls. - there is no such special method.
🗝️ Ans. iii
- it is responsible for handling the
-
👉What is inheritance?
- it is a concept of placing attributes inside objects and protecting then with dedicated methods.
- it is a concept of building new classes, based on superclasses. New subclasses extend or modify inherited traits
- it is another name for the 'has a' relation between two classes.
- it is a synonym for polymorphism.
🗝️ Ans. ii
-
👉What is polymorphism?
- it is the possibility to abstract methods from specific types to treat those types in a dedicated way.
- it is a synonym for multiple inheritance.
- it is the provision of a single interface to objects of different types.
- it is a synonym for single inheritance.
🗝️ Ans. iii
-
👉What is metaprogramming?
- it is a programming technique in which computer programs create metadata describing complex data structures like dictionaries.
- it is a polymorphic code that has the ability to decrypt itself in order to protect itself against antiviruses.
- it is a programming technique in which computer programs have the ability to modify their own code.
- it is a synonym for polymorphism.
🗝️ Ans. iii
-
👉Which of the following cannot be "pickled"?
- function definitions
- large objects (LOB) whose size exceeds 64KB.
- objects having references to other objects.
- objects already pickled.
🗝️ Ans. i
-
👉What is the dict property?
- it is a property that shows the content of every variable.
- it is a property that acts like a dictionary and combines all attributes available in your code.
- it is a built-in property owned by every Python keyword, object and instruction.
- it is a built-in special method that is responsible for supporting any operations expressed with the square
brackets.
🗝️ Ans. ii
-
👉In the following snippet, the flag parameter has been assigned a value equal to 'n' What can you say about this specific value? Select the best answer.
import shelve my_shelve = shelve.open('first_shelve.shlv', flag='n')
'n'
stands for'neutral'
- shelve will accept all data types for keys, but it will be slower in use.'n'
stands for'new'
- a new, empty database will be created.- it is incorrect.
'n'
stands for'next'
- new records will be appended to the existing ones.
🗝️ Ans. iii
-
👉Look at the following snippet. What is the expected output?
class OwnList(list): def __setitem__(self, index, value): list.append(self, value) def append(self, value): list.__setitem__(self, value) own_list = OwnList() own_list.append(3) own_list.append(2) print(own_list)
- [3, 3]
- [2, 3]
- [2, 2]
- the code is erroneous.
- [3, 2]
🗝️ Ans. iii
-
👉What is duck typing?
- it is one of the pillars of OOP, which assumes that all classes provide a consistent interface.
- it is a built-in protection against calling unknown methods. All exceptions raised by duck-typing are handled in a standard way.
- it is a fancy term for the assumption that class objects own methods that are called.
- it is a concept of attribute encapsulation. It is similar to the concept of eggs protected by their shells.
🗝️ Ans. iii
-
👉The reason for implementing abstract classes is that:
- abstract classes set requirements regarding methods that must be implemented by their subclasses.
- abstract classes decrease the code execution time.
- abstract classes help you keep your code clean, short, and self-documenting.
- abstract classes are deeper magic than 99% of users should ever worry about
🗝️ Ans. iii
-
👉Select the best statement related to a decorator.
- it is an example of 'syntactic overload' that is reserved only to closures.
- it can be a function that decorates another function with characters carrying additional meaning such as '@' or '#' or '%'
- it can be a function or a class that gains access to arguments of the function being decorated.
- it can be a function or a class that optimizes another callable object execution by limiting its functionalities.
🗝️ Ans. iii
-
👉What is serialization? Select the best answer.
- a process of assigning unique identifiers to every newly created Python object
- a process of creating Python objects based on byte sequences.
- a process of converting an object structure into a stream of bytes
- another name for the process of data transmission
🗝️ Ans. iii
-
👉Which of the following statements related to Python objects is false?
- an object is an instance of a class.
- an object is a synonym for a class.
- every object has its type.
- an object is a synonym for an instance.
🗝️ Ans. ii
-
👉Encapsulation allows for:
- controlling the access to selected attributes
- exposing the init method to consumers
- changing the type of encapsulated data; it works like a converting method.
- controlling the access to selected methods and attributes
🗝️ Ans. i
-
👉Which statement about the 'shelve' module is false?
- the 'shelve' module is built on top of the 'pickle' module, but you do not have to abide by the order of all the elements placed into the shelve object.
- the 'shelve' module is built on top of the 'pickle' module, so you must abide by the order of all the elements placed into the shelve object.
- the 'shelve' module is used for object serialization and deserialization.
- the 'shelve' module does not require importing the 'pickle' module by the programmer.
🗝️ Ans. ii
-
👉What is an instance variable?
- any kind of variable as everything in Python is an object.
- a variable that can be created only during object initialization.
- a kind of variable that exists inside an object.
- a variable that by default holds the None value as a result of variable initialization.
🗝️ Ans. iii
-
👉Exception chaining is:
- a way to compact exception information.
- a decorative statement for better exception handling.
- a way to persist details of an exception when translating it to another type of exception.
- an exception which occurs during recursion that exhausts all system resources.
🗝️ Ans. iii
-
👉Exception chain is:
- a term that describes how exception details are traveling the exception tree, upwards to the BaseException.
- a chain of trust between the subsequent exception handling methods
- a structure containing exception attributes: context and cause.
- a concept of handling exceptions raised by other exception handling code.
🗝️ Ans. iii
-
👉What is the meaning of asterisks that are present in a function definition?
- they denote complex math operators.
- they denote parameters that should be unpacked before use.
- they denote pointers as in the C or C++ languages because CPython is written in C++.
- they denote parameters of constant type and length.
🗝️ Ans. ii
-
👉When you access data stored in a shelve object, you must use the keys of specific type. What type is it?
- tuple
- integer
- string
- any mutable type
🗝️ Ans. iii
-
👉Which statement is false?
- every list could be copied using slicing [:], which results in getting an independent list object.
- deep copy might cause problems when there are cyclic references.
- compound objects should be copied using the deep copy method.
- it takes more time to make a deep copy than a shallow copy of an object.
🗝️ Ans. i
-
👉**“We're all consenting adults here” was said by:**
- Guido van Rossum, the author of Python
- John Marwood Cleese, a co-founder of 'Monty Python'
- Tim Peters, the author of 'Zen of Python'
- Uncle Bob, the developer of several software design principles
🗝️ Ans. i
-
👉Answer the following question: What is the main reason for subclassing a built-in class?
- making the code execution faster
- avoiding any intelectual rights issues
- overriding all the parent's methods
- getting a new class that can enrich the parent's methods.
🗝️ Ans. iii
-
👉What is a metaclass?
- It a description of a complex data structure such as dictionary
- a synonym for any abstract class which sets the guidelines regarding the methods required in subclasses.
- a term describing a file which contains many classes that are in the 'is-a' relation between each other.
- a class whose instances are classes.
🗝️ Ans. iii
-
👉Is a 'pickle' file format constant amongst different Python releases?
- yes, that's how the power of Python manifests itself.
- it depends on the operating system used.
- no, nobody's expected wide compatibility.
- yes, as long as the CPU architecture (32 or 64 bits) is retained.
🗝️ Ans. iii
-
👉Select the best answer to complete the following sentence:
When constructing a subclass that overrides methods from its superclass:
- you are not allowed to override all methods.
- you still have access to the superclass methods.
- you no longer have access to any of the superclass methods.
- you should leave at least one method untouched for backwards compatibility.
🗝️ Ans. ii
-
👉In the following snippet, the flag parameter has been assigned a value equal to 'c' What can you say about this specific value? Select the best answer.
import shelve my_shelve = shelve.open('first_shelve.shlv', flag='c')
- 'c' stands for 'create' - a database will be created if it does not exist.
- 'c' stands for 'critical' - a limited number of data types will be used to increase the database performance.
- it is incorrect.
- 'c' stands for 'character' - only characters (strings) can be used for shelve keys.
🗝️ Ans. i
-
👉Is it possible to instantiate an abstract class? Choose the correct answer.
- yes, every class can be instantiated.
- no, because this is not the role of abstract classes; those are blueprints that must be implemented by subclasses.
- no, because it has no method implementations at all.
- no, because it is part of a contract between the class designer and the developer.
🗝️ Ans. ii
-
👉Select the best answer to complete the following sentence:
**The *args and kwargs parameters:
- are responsible for supporting an arbitrary number of positional arguments and keyword.
- arguments, but their names cannot be changed.
- can be placed in any order in a function definition.
- are responsible for handling any number of additional arguments, placed right after the expected arguments, passed to a function called.
- are deprecated names of any function parameters, originating from Python 2.x.
🗝️ Ans. iii
-
👉What is an abstract class? Select the best answer.
- it is another name for the 'has a' relation between two abstract methods
- it is a blueprint for other classes; it cannot contain fully defined methods
- it is a blueprint for other classes; it must contain at least one abstract method
- it is a class that overloads methods derived from its superclass
- it is a class decorated with the @abstract decorator
🗝️ Ans. iii
-
👉Look at the following snippet. What is the expected output?
class OwnDict(dict): def __setitem__(self, _key, _val): super().__setitem__(_key, _val) def update(self, *args, **kwargs): for _key, _val in dict(*args, **kwargs).items(): self.__setitem__(_key, _val) own_dict = OwnDict() own_dict[4] = 1 own_dict[2] = 0.5 print(own_dict)
- the code is erroneous.
- {4: 4, 2: 2}
- {4: 1, 2: 0.5}
- {1: 4, 0.5: 2}
🗝️ Ans. iii
-
👉What is an implicit exception chaining?
- it is a way to fade an exception by replacing it with another exception to limit the memory consumed by exception details.
- it is the only way to promote exception details upwards the call stack.
- it is a situation when an exception is raised during other exception handling, so the context attribute is filled with exception details.
- it is a situation when an exception is raised intentionally during other exception handling, so the cause
attribute is filled with exception details.
🗝️ Ans. iii
-
👉What is a class? Select the best answer.
- it is another name for the Python module file.
- it expresses an idea representing a real-life entity or problem.
- it is an independent instance of any variable such as string, float, or dictionary.
- it is a synonym for an attribute.
🗝️ Ans. ii
-
👉Select the true statement about the 'self' named parameter.
- it is used as a reference to the class instance.
- it is an inherited object variable.
- it can be used before an instance is created when to access a class variable.
- this keyword is reserved for instance references and other names cannot be used for that.
🗝️ Ans. i
-
👉What is inheritance? Choose the right answer.
- a concept that allows for modeling a tight relation between two subclasses.
- a concept of encapsulating inherited data to protect them against modifications.
- a concept that allows for modeling a tight relation between a superclass and subclasses.
- a concept that allows for building classes from uncoupled elements.
🗝️ Ans. iii
-
👉What is a Python magic method?
- it is a special-purpose method that can accept any number of parameters when called.
- it is a special-purpose method that must be delivered by a developer, based on abstract blueprints.
- it is a method whose name starts and ends with a dunder.
- it is a method whose name starts and ends with a single underscore.
🗝️ Ans. iii