Which of the following loop types executes at least once, irrespective of the test condition?
- do-while loop
- for loop
- until loop
- while loop
A do-while loop in Python executes at least once, irrespective of the test condition, as the condition is checked after the loop body.
What does the finally block represent in Python's exception handling?
- A block for catching exceptions
- A block for cleaning up resources
- A block for defining custom exceptions
- A block for handling exceptions
The 'finally' block is used for cleaning up resources, such as closing files or network connections, regardless of whether an exception was raised or not.
What is the result of the operation True or False and True?
- Error
- FALSE
- TRUE
- True and False is not allowed.
The operation 'True or False and True' will result in an error because 'and' has higher precedence than 'or,' and 'and' is trying to combine a Boolean ('False') with a non-Boolean ('True').
What is the maximum length of an identifier (name of a variable, function, etc.) in Python?
- 63 characters
- 79 characters
- 99 characters
- No fixed limit
In Python, the maximum length of an identifier (variable name, function name, etc.) is 79 characters. However, it's good practice to keep identifiers concise and meaningful.
Unlike lists, tuples are _______ in Python, meaning they cannot be modified after they are created.
- Dynamic
- Immutable
- Mutable
- Static
Tuples in Python are immutable, which means their elements cannot be changed or modified after the tuple is created.
You're working on a project where a derived class Laptop inherits from two base classes: Computer and PortableDevice. Both base classes have a method named power_on(). If you call power_on() from a Laptop object without any specifications, which method will be invoked?
- An error will occur due to ambiguity in method names in the multiple inheritance scenario
- The power_on() method of the Computer class will be invoked
- The power_on() method of the Laptop class will be invoked
- The power_on() method of the PortableDevice class will be invoked
In the case of multiple inheritance, if two base classes have a method with the same name, the method of the first base class listed in the inheritance declaration is invoked. In this scenario, calling power_on() from a Laptop object without specifications will invoke the power_on() method of the Computer class.
Who is the creator of Python?
- Dennis Ritchie
- Guido van Rossum
- James Gosling
- Larry Wall
Python was created by Guido van Rossum in the late 1980s and was first released in 1991.
_______ is an environment where you can write and execute Python commands one-by-one.
- Compiler
- Debugger
- IDE
- REPL
A REPL (Read-Eval-Print Loop) is an interactive environment where you can input and execute Python commands interactively.
If d is a dictionary, the method d.______() will return a list of all the values in the dictionary.
- extract_values
- get_values
- list_values
- values
The values() method in Python returns a view object that displays a list of all the values in the dictionary. You can convert this view to a list if needed.
Which of the following can be used to import only a specific function or class from a module?
- from module import function
- import function from module
- import module
- import module.function
You can use 'from module import function' to import only a specific function or class from a module in Python.