Which built-in Python module provides mathematical functions?
- calculations
- math
- mathematics
- numbers
The 'math' module is a built-in Python module that provides a wide range of mathematical functions, such as trigonometric, logarithmic, and exponential functions.
What is the result of the intersection operation between two sets?
- A set containing all elements common to both sets
- A set containing all elements in either set
- A set containing elements unique to the first set
- An empty set
The intersection operation between two sets in Python returns a new set containing all elements that are common to both sets. If there are no common elements, it returns an empty set.
The method _______ is automatically invoked when an attribute's value is retrieved.
- call
- get
- init
- str
In Python, the __get__ method is automatically invoked when an attribute's value is retrieved using dot notation.
The philosophy of Python is summarized in a document referred to as?
- PEP Manifesto
- Python Manifesto
- Pythonic Principles
- Zen of Python
The philosophy of Python is famously summarized in the "Zen of Python" (PEP 20). It's a collection of guiding aphorisms for writing computer programs in Python, providing insights into the design principles and philosophy behind the language.
You have a list of numbers and you want to compute the sum of all positive numbers only. Which control structure can be most beneficial to achieve this?
- Conditional Statement
- For Loop
- List Comprehension
- While Loop
To compute the sum of all positive numbers in a list, a conditional statement can be most beneficial. You can iterate through the list of numbers and use a conditional statement to check if each number is positive before adding it to the sum. This allows you to selectively sum the positive numbers in the list.
In scenarios where JSON data keys are not simple strings, the json module's _______ argument can be utilized to handle non-string keys.
- ensure_ascii
- indent
- key_transform
- sort_keys
In scenarios where JSON data keys are not simple strings, the key_transform argument of the json module can be utilized to handle non-string keys by providing a custom function for key transformation.
If my_list = [10, 20, 30, 40], what does the expression my_list[-2::-2] evaluate to?
- [20, 10]
- [30, 10]
- [40, 20]
- [40, 30]
The expression my_list[-2::-2] starts at the second-to-last element of the list (which is 30), and it then steps backward by 2 positions, so it selects every second element in reverse order. Therefore, the result is [20, 10].
The pass statement in Python is essentially a _______ operation, meaning it doesn't perform any action.
- Break
- Continue
- Halt
- No-op
The 'pass' statement is a no-op or a no-operation statement. It is used as a placeholder when syntactically required but no action is desired. It doesn't perform any operation.
When you import a module using an alias, which keyword do you use?
- as
- importas
- rename
- using
When you import a module using an alias, you use the 'as' keyword. This allows you to create a shorter or more descriptive name for the module, making your code more readable and avoiding naming conflicts.
Which file mode in Python allows appending to a file in binary format?
- 'a'
- 'a+'
- 'ab'
- 'rb+'
The 'ab' file mode allows appending to a file in binary format. When you open a file in 'ab' mode, data is written in binary, making it suitable for binary file types like images or non-text data.