How can you call a function named my_function defined in a module named my_module?
- call(my_module.my_function)
- my_function(my_module)
- my_module.call_my_function()
- my_module.my_function()
To call a function defined in a module, you use the module name followed by a dot and then the function name. In this case, it would be my_module.my_function().
How can you call a method of the parent class from within a method of a child class?
- By creating an instance of the parent class
- By directly calling the parent method
- Using the parent_method() syntax
- Using the super() function
You can call a method of the parent class from within a method of the child class using the super() function followed by the method you want to call. This allows you to access and execute the parent class's method.
How can you change the order of method resolution in multiple inheritance?
- By changing the order of base classes in the class definition
- By using the @method_resolution decorator
- Using the C3 Linearization algorithm (C3 superclass linearization)
- Using the super() function
You can change the order of method resolution in multiple inheritance in Python by using the C3 Linearization algorithm (C3 superclass linearization). This algorithm calculates the order in which base classes are considered when looking up methods. The super() function is used to call methods in the method resolution order, but it doesn't change the order itself. Changing the order of base classes in the class definition directly affects method resolution but is discouraged. There is no standard @method_resolution decorator in Python.
How can you configure a Flask application to use an external configuration file?
- a. Define configuration settings directly in your Flask app's main Python file.
- b. Create a separate Python module with configuration settings and import it into your Flask app.
- c. Use environment variables for configuration.
- d. Flask doesn't support external configuration files.
You can configure a Flask application to use an external configuration file by creating a separate Python module with configuration settings and importing it into your Flask app. This allows for better separation of concerns and easier configuration management. Options a, c, and d are not recommended practices.
How can you create a decorator that takes arguments?
- By modifying the Python interpreter.
- By using the @decorator syntax with argument values.
- Decorators in Python cannot take arguments.
- Using a function that takes the decorator arguments and returns the actual decorator function.
To create a decorator that takes arguments, you can define a function that accepts those arguments and returns a decorator function. This allows you to customize the behavior of the decorator based on the arguments provided.
A ____ algorithm guarantees to run in the same time (or space) for any input of the same size.
- Deterministic
- In-Place
- Non-Deterministic
- Stable
A Deterministic algorithm guarantees to run in the same time (or space) for any input of the same size. It is predictable and has consistent performance.
A ____ in Python is a collection of key-value pairs, where the keys must be immutable.
- Dictionary
- List
- Set
- Tuple
In Python, a dictionary is a collection of key-value pairs, where the keys must be immutable (and usually unique). Tuples are immutable, making them suitable for use as dictionary keys.
A ____ is a data structure that stores elements in a linear sequence but allows additions and removals only at the start.
- Array
- Linked List
- Queue
- Stack
A Stack is a data structure that follows the Last-In-First-Out (LIFO) principle, meaning the last element added is the first to be removed. It allows additions and removals at the start, making it suitable for managing function calls, undo functionality, and more.
A ____ is a linear data structure where the elements are arranged in a circular fashion.
- Linked List
- Queue
- Ring Buffer
- Stack
A "Ring Buffer" (or Circular Buffer) is a linear data structure where elements are stored in a circular manner. It has fixed-size storage and efficiently manages data by overwriting old data when full.
A ____ is a special type of binary tree where each node has a higher (or equal) value than its children.
- AVL Tree
- Binary Search Tree (BST)
- B-Tree
- Red-Black Tree
A Binary Search Tree (BST) is a special type of binary tree where each node has a higher (or equal) value than its children. This property allows for efficient searching, insertion, and deletion of elements.