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.
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.
Which of the following is not a Python standard library?
- math
- numpy
- os
- stdlib
numpy is not a Python standard library; it's a third-party library commonly used for numerical and scientific computing. Python's standard libraries include os and math.
What is the primary use of the pass statement in Python?
- To act as a placeholder
- To indicate a successful run
- To skip a loop iteration
- To terminate the program
The primary use of the 'pass' statement in Python is to act as a placeholder. It does nothing when executed and is often used as a temporary placeholder for code that will be implemented later.
Which dictionary method provides a view on dictionary's items in the form of tuples?
- dict.items()
- dict.tuples()
- dict.values()
- dict.viewitems()
The dict.items() method returns a view object that displays a list of a dictionary's (key, value) tuple pairs, making it useful for iterating through a dictionary's items.
A colleague is seeing unexpected behavior in a function. The function uses a list as a default argument and modifies it. Every time the function is called without this argument, the list seems to retain its changes. What's the likely cause?
- Caching of previous function calls
- Incorrect usage of global variables
- Python's behavior with mutable default arguments
- The list is defined as a class attribute
The likely cause is Python's behavior with mutable default arguments. The list retains its changes because it's a mutable object shared among calls.