Bird
0
0

What will be the output of this code snippet?

medium📝 Predict Output Q5 of 15
Agentic AI - Future of AI Agents
What will be the output of this code snippet?
messages = [
  {"sender": "A1", "text": "Hi"},
  {"sender": "A2", "text": "Hello"}
]
print(messages[1]["text"])
AHi
BA2
CHello
DIndexError
Step-by-Step Solution
Solution:
  1. Step 1: Understand the data structure

    messages is a list of dictionaries; messages[1] accesses the second dictionary.
  2. Step 2: Access the 'text' key in the second dictionary

    messages[1]["text"] returns "Hello".
  3. Final Answer:

    Hello -> Option C
  4. Quick Check:

    List index 1, then dict key 'text' = Hello [OK]
Quick Trick: List index then dict key gets nested data [OK]
Common Mistakes:
  • Using index 0 instead of 1
  • Confusing keys 'sender' and 'text'
  • Expecting an error due to wrong indexing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Agentic AI Quizzes