What is the base class in Python from which all exceptions inherit?
- BaseError
- BaseException
- Error
- Exception
The base class from which all exceptions inherit in Python is 'BaseException'. It's the root of the exception hierarchy and provides common methods like str() and args for all exceptions.
Which keyword allows the creation of a block of code that always runs, regardless of exceptions?
- catch
- except
- finally
- try
In Python, the finally keyword is used to create a block of code that always runs, even if an exception is raised. It is commonly used for cleanup tasks.
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.
Which of the following concepts allows a single interface to represent different methods in derived classes?
- Abstraction
- Encapsulation
- Inheritance
- Polymorphism
Polymorphism allows a single interface or method name to represent different implementations in derived classes. It enables flexibility and dynamic method dispatch in object-oriented programming.
In Python, a dictionary can use immutable data types, like strings and tuples, as keys but not _______.
- Arrays
- Dictionaries
- Lists
- Sets
In Python, dictionaries can use immutable data types, such as strings and tuples, as keys because they are hashable and can be used to create unique hash values. However, lists are mutable, and their contents can change, so they cannot be used as dictionary keys.
What is the primary distinguishing feature of elements in a Python set?
- Indexed
- Sorted
- Unique
- Unordered
The primary distinguishing feature of elements in a Python set is that they are unique, meaning there are no duplicate elements in a set. Sets are also unordered, which means they don't have a specific order.
When you execute a Python script, what value does the name attribute hold by default for that script?
- "class"
- "init"
- "main"
- "module"
By default, when you execute a Python script, the 'name' attribute holds the value "main," indicating that the script is the main program.
The operator // performs _______ division.
- Division
- Float
- Integer
- Truncated
The operator '//' performs truncated division. It returns the integer part of the result of division, discarding the decimal part.
For a property named value, the corresponding setter decorator would be _______.
- @property.setter
- @set.value
- @set.value.setter
- @value.setter
In Python, when defining a property named 'value,' the corresponding setter decorator should be '@value.setter.'