Question 6
What will be the output of bool([]) and bool([0]) in Python?
Option C is correct. An empty container (like []) evaluates to False in a boolean context. A non-empty container (even containing 0, like [0]) evaluates to True.
What will be the output of bool([]) and bool([0]) in Python?
Option C is correct. An empty container (like []) evaluates to False in a boolean context. A non-empty container (even containing 0, like [0]) evaluates to True.
Which function converts a JSON string into a corresponding Python data structure (e.g., dictionary)?
Option A is correct. json.loads() (load string) parses a valid JSON string and converts it to Python objects (dicts, lists, etc.). json.dumps() performs the inverse.
What is the output of len({1, 2, 2, 3, 3, 3}) in Python?
Option C is correct. A Set in Python stores unique elements only. {1, 2, 2, 3, 3, 3} simplifies to {1, 2, 3}, which has a length of 3.
What does the *args syntax in a Python function definition allow?
Option E is correct. *args allows a function to accept any number of positional arguments, which are packed into a tuple inside the function. **kwargs packs keyword arguments into a dictionary.
In Python file handling, what is the behavior of opening a file in 'r+' mode?
Option B is correct. 'r+' opens an existing file for both reading and writing. The file pointer is placed at the beginning of the file, and contents are not truncated.