Print Array with Commas in Python

You have a list of monthly sales numbers in your Python script, and you want to show them nicely in a report or log file. Instead of [1200, 1500, 980], you want 1200, 1500, 980 so it looks clean in emails, dashboards, or exported text files. This sounds simple, but if you’re new to Python, printing arrays with commas can feel confusing.

In plain English, “printing an array with commas” means turning your list or NumPy array into a readable string where each value is separated by a comma. You’ll often do this when preparing data for CSV files, API payloads, or simple console output in your data analysis scripts. Think of a list of monthly sales: [1200, 1500, 980, 1750] that you want to show as 1200, 1500, 980, 1750 in your report.

In this article, I’ll show you 5 ways to print an array with commas in Python.

We’ll use the same dataset in all methods:

# Monthly sales figures in USD
sales = [1200, 1500, 980, 1750, 2100]

Method 1 – Use str.join() with a List (Pure Python)

Use this method if you want the simplest, most common way to print a list with commas using pure Python. It’s perfect when you have a list of strings or numbers and you want a clean, comma-separated string.

Step 1: Convert list elements to strings and join

# Step 0: Sample dataset
sales = [1200, 1500, 980, 1750, 2100]

# Step 1: Convert each element to string and join with commas
import builtins # not required, but shown to highlight built-in functions

sales_str = ", ".join(map(str, sales))
print(sales_str)

# Sample Output:
# 1200, 1500, 980, 1750, 2100

You can see the output in the screenshot below.

Print Array with Commas Python

How does this code work?
You start with the list sales, which contains integers. You use map() with str to convert each number to a string so join() can work with it. Then you call ", ".join(...), which takes all those strings and joins them into one string, separated by a comma and a space. Finally, print() shows the comma-separated values.

Pro Tip: Use str.join() whenever you want a fast, memory-efficient way to build strings from lists—especially useful in logging and report generation.

Method 2 – Use the sep Parameter in print()

Use this method if you want to print with commas directly, without creating a single combined string variable. This is great for quick console output when you’re debugging or inspecting data.

Step 1: Unpack the list and use sep=”,”

# Step 0: Sample dataset
sales = [1200, 1500, 980, 1750, 2100]

# Step 1: Print values separated by commas using sep
import builtins

print(*sales, sep=", ")

# Sample Output:
# 1200, 1500, 980, 1750, 2100

You can see the output in the screenshot below.

Print Array with Commas in Python

How does this code work?
The *sales syntax “unpacks” the list so each element is passed as a separate argument to print(). The sep parameter tells print() to use ", " as the separator between those arguments instead of the default space. This gives you comma-separated values directly without building an intermediate string.

Pro Tip: Use print(*my_list, sep=”, “) when you just need output on the screen and don’t care about storing the result as a string variable.

Method 3 – Use NumPy Arrays and np.array2string()

Use this method if you’re working with NumPy for data analysis or scientific computing and you want neat, comma-separated output while keeping a Python array-like look.

Step 1: Create a NumPy array from the list

import numpy as np

# Step 0: Sample dataset as a NumPy array
sales = [1200, 1500, 980, 1750, 2100]
sales_array = np.array(sales)

# Step 1: Convert array to a string with commas
sales_str = np.array2string(sales_array, separator=", ")
print(sales_str)

# Sample Output:
# [1200, 1500, 980, 1750, 2100]

You can see the output in the screenshot below.

Print Python Array with Commas

How does this code work?
You import numpy as np and convert the sales list into a NumPy array using np.array(). Then you call np.array2string(), passing the array and the separator=", " parameter. This returns a string representation of the array where elements are separated by commas, and print() displays it.

Pro Tip: np.array2string() is ideal when you want a nicely formatted representation of arrays for logs or reports; you can also control line width and other formatting options

Method 4 – Use str.join() Directly on a NumPy Array

Use this method if you want a plain comma-separated string from a NumPy array, without square brackets. This is handy when exporting to CSV or sending data through an API.

Step 1: Convert NumPy array elements to strings and join

import numpy as np

# Step 0: Sample dataset as a NumPy array
sales = [1200, 1500, 980, 1750, 2100]
sales_array = np.array(sales)

# Step 1: Use astype(str) and str.join()
sales_str = ", ".join(sales_array.astype(str))
print(sales_str)

# Sample Output:
# 1200, 1500, 980, 1750, 2100

How does this code work?
You create sales_array using np.array(). Then you call sales_array.astype(str) to convert each element to a string so they can be joined. Finally, you use “, “.join(…) to build one comma-separated string and print it. This removes the brackets and looks like a typical CSV-style line.blog.

Pro Tip: Use array.astype(str) before str.join() when working with NumPy arrays, so you don’t run into type errors and you get clean string output.

Method 5 – Use a Simple for Loop (Full Control)

Use this method if you want maximum control over formatting, such as adding prefixes, suffixes, or custom rules. It’s also helpful if you’re still getting comfortable with loops in Python.

Step 1: Build the comma-separated string manually in a loop

# Step 0: Sample dataset
sales = [1200, 1500, 980, 1750, 2100]

# Step 1: Manually build the string with commas
import builtins

result = ""
for i in range(len(sales)):
result += str(sales[i])
if i < len(sales) - 1:
result += ", "
print(result)

# Sample Output:
# 1200, 1500, 980, 1750, 2100

How does this code work?
You start with an empty string result. You loop over the indexes of the Python list using range(len(sales)). For each index, you append the current value converted to a string. If it’s not the last element, you also append ", " so commas go between values only. After the loop, print(result) shows the final comma-separated string.

Pro Tip: A manual loop is slower than str.join() but gives you full control, use it when you need complex formatting rules, not just simple separators.

Things to Keep in Mind

  • Empty lists or arrays – If your list or NumPy array is empty, methods like str.join() will return an empty string. Handle this case to avoid printing blank lines in logs.
  • Non-string elements – str.join() works only with strings. Always convert numbers using map(str, iterable) or astype(str) for arrays before joining, or you’ll get a TypeError.
  • NumPy vs pure Python – Use NumPy methods like np.array2string() when you’re already working with NumPy arrays. Stick to lists and str.join() if you don’t need external libraries.
  • Python 2 vs Python 3 – In Python 3, print() is a function and supports the sep parameter. If you copy old Python 2 examples without parentheses, they won’t work in modern Python.
  • Performance for large data – For big lists (thousands of elements), str.join() is faster and more memory-efficient than building strings in a loop with +=. Use joins for high-volume logging or report generation.
  • Formatting for CSV – If you plan to save data as CSV files later, keep your separator consistent (usually ",") and consider using the csv library for more robust handling of edge cases like commas inside values.

You’ve now seen 5 practical ways to print an array with commas in Python, using both pure Python and NumPy. Use str.join() for most cases, print(…, sep=”, “) for quick console output, and NumPy methods when you’re deep into array-based data analysis. I hope you found this article helpful.

You may also read:

51 Python Programs

51 PYTHON PROGRAMS PDF FREE

Download a FREE PDF (112 Pages) Containing 51 Useful Python Programs.

pyython developer roadmap

Aspiring to be a Python developer?

Download a FREE PDF on how to become a Python developer.

Let’s be friends

Be the first to know about sales and special discounts.