I will help you to understand how to print an array with commas in Python in this tutorial. As a data scientist working on a project for a US-based company, I recently faced an issue where I needed to display the elements of a NumPy array as a comma-separated string. After researching various methods, I discovered several effective ways to achieve this. I will explain these techniques, along with examples and screenshots of executed example code.
Convert NumPy Array to Comma-Separated String in Python
When working with NumPy arrays, you can use the np.array2string() function to convert the Python array to a comma-separated string. Here’s an example.
import numpy as np
cities = np.array(["New York", "Los Angeles", "Chicago", "Houston", "Phoenix"])
city_string = np.array2string(cities, separator=", ")
print(city_string)Output:
['New York', 'Los Angeles', 'Chicago', 'Houston', 'Phoenix']Let me show you the screenshot of the example code which I executed.

To remove the square brackets from the output, you can set the formatter parameter to None and use string slicing to remove the brackets as shown.
city_string = np.array2string(cities, separator=", ", formatter={'str_kind': lambda x: x})[1:-1]
print(city_string)Output:
New York, Los Angeles, Chicago, Houston, PhoenixLet me show you the screenshot of the example code which I executed.

Check out How to Convert Python Dict to Array
Convert Python List to Comma-Separated String
If you have a Python list instead of a NumPy array, you can use the join() method to convert the list to a comma-separated string. Here’s an example:
states = ["California", "Texas", "Florida", "New York", "Illinois"]
state_string = ", ".join(states)
print(state_string)Output:
California, Texas, Florida, New York, IllinoisLet me show you the screenshot of the example code which I executed.

The join() method takes an iterable (such as a list) and joins its elements into a string, using the specified separator.
Read How to Print Duplicate Elements in Array in Python
Print Python List with Commas Using print()
Another way to print a list with commas is by using the print() function with the sep parameter. This method works for both lists and NumPy arrays. Here’s an example:
presidents = ["George Washington", "John Adams", "Thomas Jefferson", "James Madison", "James Monroe"]
print(*presidents, sep=", ")Output:
George Washington, John Adams, Thomas Jefferson, James Madison, James MonroeThe * before the list name unpacks the list, passing each element as a separate argument to the print() function. The sep the parameter specifies the separator to use between the elements, which in this case is a comma followed by a space.
Check out How to Update an Array in Python
Pandas DataFrame Column to Comma-Separated String in Python
When working with Pandas DataFrames, you may need to convert a column containing strings to a comma-separated list. You can achieve this using the str.cat() method.
import pandas as pd
data = {
"Name": ["John Smith", "Emma Davis", "Michael Johnson", "Olivia Williams", "William Brown"],
"Age": [28, 32, 45, 37, 51]
}
df = pd.DataFrame(data)
name_list = df['Name'].str.cat(sep=', ')
print(name_list)Output:
John Smith, Emma Davis, Michael Johnson, Olivia Williams, William BrownRead How to Find the Sum of an Array in Python
Conclusion
In this tutorial, I have explained how to print an array with commas in Python. We explored several effective ways to achieve this, like convert numPy array to comma separated string, where we used np.array2string() function to convert the Python array, converting list to comma separated String using the join() method is another method, print Python list with commas using print() is also covered in this article, we also discussed, pandas DataFrame column to comma separated string in Python.
You may also like to read:
- How to Remove Duplicates from an Array in Python
- How to Check if an Array Index Exists in Python
- How to Remove NaN from Array in Python
- How to Create an Array of Zeros in Python

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.