Why does printing a Python list of strings output each element on a new line?
💡 Model Answer
When you call print() on a list, Python prints the list’s representation, which includes brackets and commas, all on one line. However, if you iterate over the list and call print() on each element, each print statement ends with a newline, so each string appears on its own line. The behavior you described—one element per line—occurs when the code explicitly prints each element separately, not when printing the list object itself. To print the entire list on a single line, use print(my_list) or join the elements: print('\n'.join(my_list)) for a newline‑separated string.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI — Starts at ₹500