Bird
0
0

What is the output of the following code?

medium📝 Predict Output Q13 of 15
Python - Input and Output

What is the output of the following code?

print("{0} + {1} = {2}".format(3, 4, 3+4))
A"7 + 7 = 14"
B"3 + 4 = 7"
C"3 + 4 = 3+4"
D"{0} + {1} = {2}"
Step-by-Step Solution
Solution:
  1. Step 1: Understand placeholders and arguments

    The placeholders {0}, {1}, {2} are replaced by the first, second, and third arguments of format(), which are 3, 4, and 7 respectively.
  2. Step 2: Substitute values into the string

    Replacing placeholders gives the string "3 + 4 = 7".
  3. Final Answer:

    "3 + 4 = 7" -> Option B
  4. Quick Check:

    Placeholders replaced by arguments [OK]
Quick Trick: Numbered placeholders match format() arguments by position [OK]
Common Mistakes:
MISTAKES
  • Printing placeholders literally without replacement
  • Confusing expression with string output
  • Mixing up argument order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes