OA. free
Free
Micron Core Computer Science Core Computer Science Medium

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)
Choose one option.
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:

  1. x = ['apple', 'banana'] — list is created with two string elements
  2. 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
  3. print(True) outputs: True