how to print array integer without [] bracket in python like result = 1,2,3,4,5

+3 votes
Aug 4, 2018 in Python by Abhishek
• 240 points

2 answers to this question.

+1 vote
Best answer

Hey @abhijmr.143, you can print array integers in the format mentioned in your question with the following code:


from __future__ import print_function 
a = [1,2,3,4,5]
for value in a: 
    print(value, end=',') 
print(" ") 




from __future__ import print_function #This line is only needed in Python 2.X, you can skip this line if you are using python 3.X
a = [1,2,3,4,5] #array initialization
for value in a: #loop to print all array elements
    print(value, end=',') #This line prints the array integers with a comma(,) as its suffix and prints a comma even after the last integer
print("\b",end="") #This line is used to move the cursor to the last printed character
print(" ") #This line replaces the comma(,) printed after the last integer with a blank space
answered Aug 4, 2018 by Omkar
• 69,030 points

edited Aug 8, 2018 by Omkar
+1 vote

from __future__ import print_function

data = [7, 7, 7, 7]
print(*data, sep='')
answered Aug 6, 2018 by Sushmita
• 6,890 points
This code will print the output as follows:

To print the data as mentioned in the question, edit the last line of your code as follows:
print(*data, sep=',')

Related Questions In Python

+2 votes
11 answers
0 votes
1 answer

How to create a function like f(y) = xy^2 in Python?

This is very easy. have a look ...READ MORE

answered Aug 5, 2019 in Python by Neel
• 3,010 points

edited Aug 6, 2019 by Kalgi 60 views
+4 votes
7 answers
+1 vote
1 answer

How to print first character of each word in upper case of a string in Python

You can use split() using space as ...READ MORE

answered Jun 1, 2018 in Python by george
• 200 points
0 votes
1 answer

How to use string.replace() in python 3.x

replace() is a method of <class 'str'> ...READ MORE

answered Aug 3, 2018 in Python by Priyaj
• 57,660 points
+1 vote
1 answer

How to print an error in Python?

For Python 2.6 and later and Python ...READ MORE

answered Aug 23, 2018 in Python by Priyaj
• 57,660 points
0 votes
1 answer

How to Print a List in Python

ou are using Python 2.x syntax with ...READ MORE

answered Aug 31, 2018 in Python by charlie_brown
• 7,780 points
0 votes
1 answer

How to save Numpy array as image in python?

If you have matplotlib, you can do: import ...READ MORE

answered Nov 16, 2018 in Python by Nymeria
• 3,520 points
0 votes
2 answers
0 votes
1 answer

How to add integer to python array?

You have defined a numpy array but ...READ MORE

answered Feb 3, 2019 in Python by Omkar
• 69,030 points