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
4,556 views

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:

Code:

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

Output:

1,2,3,4,5

Explanation:

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:
7777

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 71 views
0 votes
1 answer

How to write a code In Python where input will be 1 then the output will be 2?

You can go through this:  def num(number): ...READ MORE

answered Oct 6 in Python by Gitika
• 42,520 points
26 views
0 votes
1 answer

What will be the output of below code and why? x=[1,2,3,4,5] print(x.insert(2,3))

If you write x.insert(2,3) and then print x ...READ MORE

answered Oct 14 in Python by Gitika
• 42,520 points
38 views
+4 votes
7 answers
+1 vote
2 answers

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

class Solution:     def firstAlphabet(self, s):             self.s=s              k=''              k=k+s[0]              for i in range(len(s)):                     if ...READ MORE

answered 1 day ago in Python by Anurag
5,605 views
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,700 points
303 views
+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,700 points
685 views
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
3,010 views