Given a scenario where a system should notify a user if the storage space goes below 5% or above 95%. Which of the following combinations of operators will be suitable for the condition?
- if storage < 5 or storage > 95:
- if storage <= 5 or storage >= 95:
- if storage > 5 and storage < 95:
- if 5 <= storage <= 95:
To check if the storage space goes below 5% or above 95%, you should use the condition if storage <= 5 or storage >= 95:. This condition covers both cases, ensuring that the system notifies the user when the storage falls below 5% or exceeds 95%. The other options do not provide the correct combination of operators for this scenario.
Which Python method is executed when the context of a with statement is entered?
- __enter__()
- __exit__()
- __init__()
- __open__()
The __enter__() method is executed when the context of a 'with' statement is entered. It typically sets up the required resources or context for the code block within the 'with' statement.
Packages in Python provide a way of organizing related modules into a single _______ directory hierarchy.
- File System
- Folder
- Namespace
- Package
Packages in Python help organize related modules into a single folder hierarchy, making it easier to manage and access them in a structured way.
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.
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].