In the context of nested loops, how does the break statement operate?
- It exits all loops
- It exits the innermost loop
- It only exits the outermost loop
- It terminates the entire program
The 'break' statement, in the context of nested loops, exits only the innermost loop where it is encountered, allowing outer loops to continue.
Python functions can have default argument values, defined using the _______ syntax in the function header.
- default
- initial
- optional
- default_value
Python functions can have default argument values, defined using the optional syntax in the function header. These default values are used when the function is called without providing values for these arguments.
How do you create an empty set in Python?
- empty_set = []
- empty_set = set()
- empty_set = {None}
- empty_set = {}
To create an empty set in Python, you should use the set() constructor, like this: empty_set = set(). Using {} creates an empty dictionary, not a set.
In terms of function execution, what is the difference between yield and return?
- 'return' immediately terminates the function, returning a value to the caller.
- 'return' suspends the function's state, allowing it to resume execution later.
- 'yield' immediately terminates the function, returning a value to the caller.
- 'yield' suspends the function's state, allowing it to resume execution later.
'yield' and 'return' serve different purposes in Python. 'yield' is used in generators to pause execution and later resume it, whereas 'return' terminates the function.
You need to use a data structure as keys for a dictionary, and it must hold multiple items. Which one would you choose between lists and tuples?
- Both lists and tuples
- List
- Neither lists nor tuples
- Tuple
Tuples are the preferred choice as keys for dictionaries because they are immutable. Lists, on the other hand, are mutable and cannot be used as dictionary keys. Immutability ensures that the keys remain consistent, preventing unexpected behavior in the dictionary.
To write a list of dictionaries to a CSV file, one can use the DictWriter class from the _______ module.
- csv
- data
- excel
- pandas
To write a list of dictionaries to a CSV file in Python, you can use the csv module. Specifically, the DictWriter class from the csv module allows you to write dictionaries as rows in a CSV file, where the keys of the dictionaries are used as column headers. This is a common technique when working with tabular data in Python.
For method overriding to occur, the method in the derived class must have the same _______ and return type as the method in the base class.
- Method name and arguments
- Method name and parameters
- Method signature and name
- Method signature and parameters
Method overriding in Python requires that the method in the derived class has the same method name and arguments (parameters) as the method in the base class.
In type hinting, if a function is expected not to return any value, the return type should be hinted as _______.
- Empty
- None
- Void
- nan
In type hinting, if a function is expected not to return any value, the return type should be hinted as 'None'. 'None' signifies the absence of a return value.
For loops in Python utilize the ______ method internally to iterate over items.
- enumerate
- iterate
- loop
- range
For loops in Python utilize the enumerate method internally to iterate over items. enumerate returns both the index and the value of each item in the sequence, making it useful for tracking positions in the loop.
How does Python internally represent a float value?
- ASCII Encoding
- IEEE 754
- Two's Complement
- Unicode Encoding
Python internally represents a float value using the IEEE 754 standard for floating-point arithmetic.