Bird
0
0

What is the output of the following code?

medium📝 Predict Output Q4 of 15
Python - Operators and Expression Evaluation
What is the output of the following code?
fruits = ['apple', 'banana', 'cherry']
print('banana' in fruits)
print('grape' not in fruits)
ATrue\nFalse
BTrue\nTrue
CFalse\nTrue
DFalse\nFalse
Step-by-Step Solution
Solution:
  1. Step 1: Check if 'banana' is in the list

    'banana' is in the list, so 'banana' in fruits is True.
  2. Step 2: Check if 'grape' is not in the list

    'grape' is not in the list, so 'grape' not in fruits is True.
  3. Final Answer:

    True\nTrue -> Option B
  4. Quick Check:

    Membership checks = A [OK]
Quick Trick: Check each membership separately for True/False [OK]
Common Mistakes:
MISTAKES
  • Assuming 'not in' returns False if item missing
  • Confusing True/False outputs
  • Ignoring newline in output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes