Print array items without commas in Python

This tutorial will see how to print the array elements without commas in Python. Arrays are the data structures that store data of similar data type. Now to print the array elements without commas we will convert the array into a string and then print that string.

join() method in Python

char.join(object) is the method which takes argument of iterable objects like array, list, set etc. and converts them to a single string by joining their elements with the character specified. You can use any character as a separator. In this case, we want to print the array elements without commas so we will specify the separator as a blank or space.

Array: In Python array can be defined by using array function from numpy library.

Python code for printing array elements without commas:

import numpy as np
fruits = np.array(["Orange", "Apple", "Banana", "Mango"])
print(' '.join(fruits))


Orange Apple Banana Mango

Also refer to Print NumPy array without commas in Python

Leave a Reply

Your email address will not be published. Required fields are marked *