Bird
0
0

Which of the following is the correct syntax to format a string with two placeholders?

easy📝 Syntax Q3 of 15
Python - Input and Output

Which of the following is the correct syntax to format a string with two placeholders?

A"{0} and {1}".format()
B"{0} and {1}".format("apple")
C"{} and {}".format("apple", "banana")
D"{1} and {0}".format("apple")
Step-by-Step Solution
Solution:
  1. Step 1: Check number of placeholders and arguments

    Two placeholders {} and two arguments "apple", "banana" match in "{} and {}".format("apple", "banana").
  2. Step 2: Verify syntax correctness

    "{} and {}".format("apple", "banana") uses correct syntax with positional placeholders and matching arguments.
  3. Final Answer:

    "{} and {}".format("apple", "banana") -> Option C
  4. Quick Check:

    Number of placeholders = number of arguments [OK]
Quick Trick: Match placeholders count with format() arguments [OK]
Common Mistakes:
MISTAKES
  • Not providing enough arguments
  • Using placeholders with wrong indices
  • Calling format() without arguments

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes