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
8,049 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 5, 2018 by Omkar
• 69,230 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,920 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

+1 vote
12 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,020 points

edited Aug 6, 2019 by Kalgi 2,057 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 7, 2020 in Python by Gitika
• 65,890 points
1,162 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, 2020 in Python by Gitika
• 65,890 points
4,207 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 Oct 28, 2020 in Python by Anurag
12,256 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
• 58,100 points
1,033 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
• 58,100 points
1,387 views
–1 vote
2 answers
0 votes
1 answer

How to add integer to python array?

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

answered Feb 4, 2019 in Python by Omkar
• 69,230 points
5,303 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP