Home >Backend Development >Python Tutorial >How to Print a Python List Without Braces and on a Single Line?
Eliminating Braces and Printing Lists in a Single Row
Given a list in Python, such as:
names = ["Sam", "Peter", "James", "Julian", "Ann"]
Ordinarily, printing this list would produce the output:
["Sam", "Peter", "James", "Julian", "Ann"]
However, to format the list without brackets and in a single row, follow these steps:
string_names = ', '.join(names)
print(string_names)
This will produce the desired output:
Sam, Peter, James, Julian, Ann
The above is the detailed content of How to Print a Python List Without Braces and on a Single Line?. For more information, please follow other related articles on the PHP Chinese website!