How would you optimize a Python function that is found to be CPU-bound during profiling?
- a) Use a Just-In-Time (JIT) compiler like PyPy.
- b) Increase the number of threads to parallelize the code.
- c) Optimize the algorithm or use data structures that are more efficient.
- d) Use a faster computer for running the code.
When a Python function is CPU-bound, the most effective optimization is usually to optimize the algorithm or use more efficient data structures. JIT compilation (a) can help in some cases, but it may not be as effective as algorithmic improvements. Increasing the number of threads (b) might help if the code can be parallelized, but this is not always the case. Using a faster computer (d) is generally not a solution to CPU-bound code as it doesn't address the underlying inefficiencies.
In object-oriented programming in Python, ____ refers to the class that a class inherits from.
- base class
- parent class
- subclass
- superclass
In Python, the term "base class" refers to the class that a class inherits from. It's also commonly called a "parent class" or "superclass."
In object-oriented programming, ____ refers to the bundling of data and methods that operate on that data into a single unit.
- Abstraction
- Encapsulation
- Inheritance
- Polymorphism
In object-oriented programming, encapsulation refers to the concept of bundling data (attributes) and methods (functions) that operate on that data into a single unit, known as a class. This helps in data hiding and controlling access to an object's internals.
In Pandas, ____ is used to concatenate two or more DataFrames along a particular axis.
- combine
- concat
- join
- merge
In Pandas, the concat function is used to concatenate (combine) two or more DataFrames along a specified axis (either rows or columns). It is a powerful tool for combining data in various ways.
In Pandas, how can you filter the rows of a DataFrame where the value in a specific column is greater than a threshold?
- df.apply('column_name > threshold')
- df.filter('column_name > threshold')
- df.select('column_name').where('value > threshold')
- df[df['column_name'] > threshold]
To filter rows in a Pandas DataFrame where the value in a specific column is greater than a threshold, you can use boolean indexing. This is achieved by specifying the condition inside square brackets.
In Pandas, how do you access the first five rows of a DataFrame?
- df.head()
- df.iloc[:5]
- df.loc[:5]
- df[0:5]
To access the first five rows of a Pandas DataFrame, you should use the head() method, like df.head(). This method returns the top N rows (default is 5) of the DataFrame.
In pytest, the ____ fixture is used to execute specific finalization code after the test function has completed.
- cleanup
- finalize
- teardown
- yield_fixture
In pytest, the teardown fixture is used to execute finalization code after the test function has completed its execution. This allows you to perform cleanup tasks or teardown actions after the test has run, such as closing a database connection or cleaning up temporary files.
In pytest, the ____ fixture is used to pass command-line options to test functions.
- @pytest.cmdline
- @pytest.config
- @pytest.fixture(params)
- @pytest.options
In pytest, the @pytest.config fixture is used to pass command-line options and configuration values to test functions. This allows you to customize the behavior of your tests based on configuration settings.
In pytest, the ____ marker is used to skip a test function under certain conditions.
- @pytest.ignore
- @pytest.run
- @pytest.skip
- @pytest.xfail
In pytest, the @pytest.skip marker is used to skip a test function when certain conditions are met. This allows you to selectively skip tests based on runtime conditions or configurations.
In Python, ____ is used to access the attributes and methods of a class.
- Class
- Dot notation
- Inheritance
- Object
In Python, you use the dot notation (.) to access the attributes and methods of a class. For example, object.attribute or object.method().