Which Python feature would you use to modify the behavior of a function or method?
- Decorators
- Encapsulation
- Inheritance
- Polymorphism
In Python, decorators are used to modify the behavior of functions or methods. They allow you to add functionality to existing code without modifying its structure. Decorators are often used for tasks like logging, authentication, and more.
Which Python framework allows you to integrate Python back-end code with HTML, CSS, and JavaScript for web development?
- Bottle
- Django
- Flask
- Pyramid
Flask is a micro web framework for Python that allows you to integrate Python back-end code with HTML, CSS, and JavaScript to build web applications. Django, Pyramid, and Bottle are also Python web frameworks, but Flask is known for its simplicity and flexibility, making it suitable for beginners.
Which Python keyword is primarily used in generator functions to yield values?
- break
- continue
- return
- yield
The yield keyword is used in generator functions to yield values one at a time. It allows the function to pause its execution state and resume it when the next value is requested, making generators memory-efficient and suitable for iterating over large datasets.
Which Python keyword is used to define a base class?
- class
- inherit
- parent
- superclass
In Python, the class keyword is used to define a class, including a base class (parent class). You create a base class by defining a class using the class keyword.
Which Matplotlib function allows plotting data points in the form of a two-dimensional density plot?
- contour()
- heatmap()
- hist2d()
- scatter()
The heatmap() function in Matplotlib allows you to create a two-dimensional density plot. It is useful for visualizing the distribution and density of data points in a heatmap-like format.
Which method can be used to get the value for a given key from a dictionary, and if the key is not found, it returns a default value?
- fetch()
- get()
- retrieve()
- value()
The get() method of a dictionary allows you to retrieve the value associated with a given key. If the key is not found, it returns a default value, which can be specified as a second argument to get(). This is a useful way to avoid KeyError exceptions. The other options are not valid methods for this purpose.
Which method in Scikit-learn would you use to tune hyperparameters of a model?
- fit()
- gradient_boosting()
- GridSearchCV
- predict()
GridSearchCV is used in Scikit-learn for hyperparameter tuning. It performs an exhaustive search over specified hyperparameter values to find the best combination for the model.
Which method is commonly used to send data from a web form to a Python back-end?
- FETCH
- GET
- POST
- PUT
The common method used to send data from a web form to a Python back-end is POST. When a user submits a form, the data is sent to the server using the POST method, which allows for secure transmission of sensitive information. GET is used to retrieve data, while PUT and FETCH serve other purposes in web development.
Which Flask function is used to start the development server of a Flask application?
- begin()
- launch()
- run()
- start()
The correct function to start the development server in Flask is run(). This function is typically called at the end of a Flask script to launch the server and make the web application accessible.
Which function in Matplotlib is primarily used to create bar plots?
- plt.bar()
- plt.hist()
- plt.plot()
- plt.scatter()
In Matplotlib, the plt.bar() function is primarily used to create bar plots. Bar plots are used to represent categorical data with rectangular bars, making it easy to compare different categories.