Skip to main content

Posts

Showing posts with the label MCQ

Python MCQ

 Question 1: What is the output of the following Python code? ```python numbers = [1, 2, 3, 4, 5] result = sum(numbers) print(result) ``` A) 15 B) 10 C) 5 D) Error Answer: A) 15 Explanation: The code calculates the sum of all numbers in the `numbers` list using the `sum()` function and then prints the result, which is 15. ------------------------------------------------------------------------- Question 2: What does the following Python code do? ```python text = "Hello, World!" result = text.split(",") ``` A) Splits the text at commas and stores the parts in a list. B) Reverses the text. C) Removes all commas from the text. D) Raises an error. Answer: A) Splits the text at commas and stores the parts in a list. Explanation: The `split(",")` method splits the text at each comma and returns a list containing the parts. In this case, the result will be `['Hello', ' World!']`. --------------------------------------------------------------------...