Bird
0
0

Given this Python code snippet, what will be the output?

medium📝 Predict Output Q4 of 15
Agentic AI - Agent Safety and Guardrails
Given this Python code snippet, what will be the output?
output = "This is a secret message"
banned_words = ["secret", "hidden"]
filtered = any(word in output for word in banned_words)
print(filtered)
AFalse
BTrue
CNone
DError
Step-by-Step Solution
Solution:
  1. Step 1: Check if any banned word is in output

    The word "secret" is in the output string, so any() returns True.
  2. Step 2: Understand print output

    Printing filtered will print True because the condition is met.
  3. Final Answer:

    True -> Option B
  4. Quick Check:

    Output contains banned word = True [OK]
Quick Trick: any() returns True if any banned word is found [OK]
Common Mistakes:
  • Assuming output is False if only one banned word matches
  • Confusing any() with all()
  • Expecting an error due to list usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Agentic AI Quizzes