Bird
0
0

Which of the following statements correctly checks if the string 'apple' is in the list fruits = ['apple', 'banana', 'cherry'] using pytest assertions?

easy🧠 Conceptual Q11 of 15
PyTest - Writing Assertions
Which of the following statements correctly checks if the string 'apple' is in the list fruits = ['apple', 'banana', 'cherry'] using pytest assertions?
Aassert fruits in 'apple'
Bassert 'apple' not in fruits
Cassert 'apple' in fruits
Dassert 'apple' == fruits
Step-by-Step Solution
Solution:
  1. Step 1: Understand the membership check

    The in keyword checks if an item exists inside a collection like a list.
  2. Step 2: Apply the correct assertion

    To confirm 'apple' is in the list, use assert 'apple' in fruits. This passes if 'apple' is found.
  3. Final Answer:

    assert 'apple' in fruits -> Option C
  4. Quick Check:

    Use in to check presence [OK]
Quick Trick: Use 'in' to check presence, 'not in' for absence [OK]
Common Mistakes:
MISTAKES
  • Using 'not in' instead of 'in' when checking presence
  • Reversing the order like 'fruits in apple'
  • Using equality instead of membership check

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes