Bird
0
0

You want to print a list of items on the same line separated by commas, but without a trailing comma at the end. Which code achieves this?

hard📝 Application Q8 of 15
Python - Input and Output
You want to print a list of items on the same line separated by commas, but without a trailing comma at the end. Which code achieves this?
Aprint(*items, sep=', ')
Bprint(items, sep=', ')
Cprint(items, end=', ')
Dprint(', '.join(items))
Step-by-Step Solution
Solution:
  1. Step 1: Understand how to print list items separated by commas

    Using join() on a list of strings creates a single string with commas between items and no trailing comma.
  2. Step 2: Analyze other options

    print(*items, sep=', ') prints items separated by commas but no trailing comma; however, if items are not strings, it fails. print(items, sep=', ') prints the list as one object. print(items, end=', ') adds comma after entire list.
  3. Final Answer:

    print(', '.join(items)) -> Option D
  4. Quick Check:

    Use join() to format list without trailing comma [OK]
Quick Trick: Use join() to print list with separators cleanly [OK]
Common Mistakes:
MISTAKES
  • Using sep with list object directly
  • Forgetting to unpack list with *
  • Adding trailing comma with end parameter

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes