QUESTION 29 What will be the output of the following Python Program?
Micron technical mcq question, verified with a worked answer. Free to practise - no sign-up.
QUESTION 29
What will be the output of the following Python Program?
x = ['apple', 'banana']
print('pineapple' not in x)
Show answer & explanation
Answer: A. True
The expression 'pineapple' not in x checks whether the string 'pineapple' is absent from the list x. Since x contains only ['apple', 'banana'] and 'pineapple' is not in the list, the condition evaluates to True. The print statement outputs True.
Step-by-step Derivation:
Step-by-step execution:
- x = ['apple', 'banana'] — list is created with two string elements
- Evaluate: 'pineapple' not in x
- Check if 'pineapple' exists in x → No, it does not
- The 'not in' operator returns True when the item is absent
- print(True) outputs: True