How can you implement a switch-case like behavior in Python?
- By importing the 'switch' module
- By using if-elif-else statements
- By using the 'switch' keyword
- Python does not support switch-case
Python does not have a built-in 'switch' statement, but you can achieve similar behavior using if-elif-else statements to evaluate multiple conditions.
How can you achieve the symmetric difference of two sets in Python?
- Using the difference() method
- Using the intersection() method
- Using the symmetric_difference() method
- Using the union() method
To find the symmetric difference of two sets in Python, you can use the symmetric_difference() method. It returns a new set containing elements that are unique to each of the two sets, excluding the elements they have in common.
What is the purpose of the import keyword in Python?
- To create custom functions
- To declare class names
- To define variables
- To include external modules
The 'import' keyword in Python is used to include external modules or libraries, making their functionality available in your script.
What happens if you try to raise an exception using the raise keyword without specifying an exception?
- It raises a 'NameError'
- It raises a 'SyntaxError'
- It raises a 'TypeError'
- It raises a generic 'Exception'
If you raise an exception using the 'raise' keyword without specifying an exception type, it raises a generic 'Exception' with no message.
To make a module's functions directly accessible, you can use the _______ statement.
- From
- Import
- Include
- Require
To make a module's functions directly accessible, you can use the 'from' statement. It allows you to import specific functions or objects from a module into your current namespace.
In OOP, what is the term for the class from which the derived class inherits?
- Base Class
- Parent Class
- Primary Class
- Superclass
The class from which a derived class inherits is known as the 'Base Class' or 'Parent Class.' In Python, it's also referred to as the superclass.
What does the @property decorator do in a Python class?
- It defines a class method
- It defines a getter method
- It defines a setter method
- It defines a static method
The @property decorator defines a getter method for a class attribute, allowing you to access it as if it were an instance variable.
In a for loop, what does the range(3, 8, 2) function return?
- [2, 4, 6, 8]
- [3, 4, 5, 6, 7]
- [3, 5, 7]
- [3, 5]
range(3, 8, 2) generates values starting from 3 (inclusive) up to 8 (exclusive) with a step size of 2, resulting in [3, 5, 7].
Which built-in function can be used to create a set in Python?
- create_set()
- make_set()
- new_set()
- set()
The built-in function set() is used to create a set in Python. You can use it by calling set(), and you can pass an iterable (like a list) as an argument to initialize the set with elements.
The json module provides two methods for JSON serialization: dump() and _______.
- dumps()
- save()
- serialize()
- write()
The json module in Python provides two methods for JSON serialization: dump() and dumps(). The dump() method is used to serialize a Python object to a JSON file, while dumps() is used to serialize a Python object to a JSON-formatted string. Both methods are essential for working with JSON data in Python.