Bird
0
0

What will this Python code print?

medium📝 Predict Output Q13 of 15
Python - Basics and Execution Environment
What will this Python code print?
name = 'Alice'
print(f'Hello, {name}!')
AHello, Alice!
BHello, name!
CHello, {name}!
DError: invalid syntax
Step-by-Step Solution
Solution:
  1. Step 1: Understand f-string usage and replace variable

    The code uses an f-string to insert the value of variable name inside the string. Variable name is 'Alice', so the output becomes 'Hello, Alice!'.
  2. Final Answer:

    Hello, Alice! -> Option A
  3. Quick Check:

    f-string inserts variable value [OK]
Quick Trick: f-strings show variable values inside strings [OK]
Common Mistakes:
MISTAKES
  • Thinking it prints the variable name as text
  • Confusing f-string syntax with regular strings
  • Expecting a syntax error due to unfamiliar syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes