Python how to print output

Asked

Viewed 322 times

4

How can I print a list this way, example:

l=[4,26,32]

I want to print the output as follows:

4 26 32

No comma and a blank space on the same line. Grateful from now on.

5 answers

7

  • 1

    Thank you, it’s very helpful.

  • To whom you gave -1, if you have something I can improve on the answer, please leave a comment.

1

There are some ways for you to resolve this issue.

1st form of resolution:

In this form you implement a loop for, iterate over the list l and displays each element of the list with the aid of end=' '.

l = [4, 26, 32]

for c in l:
    print(c, end=' ')
print()

2nd form of resolution:

l = [4, 26, 32]
print(*l)

1

This is simple!

print (str(l[0]) + ' ' + str(l[1]) + ' ' + str(l[2]))

Listing:

for i in l:
   print (str(i) + ' ', end="");
  • I used three numbers as an example,?

  • Something that holds for any number of elements on the list.

  • I edited the answer.

  • Thank you very much, it’s very helpful!

  • When a reply satisfies you, you give a +1 vote on the answer!

0

You can scroll through a list in Python using the repeat structure For N in L: that is to say Percorra todas as posições da minha lista e me retorne N, after that just perform an output of N within the repeating structure.

I advise that video classroom if you want to learn a little more about For.

  • 1

    While this link may answer the question, it is best to include the essential parts of the answer here and provide the link for reference. Replies per link only can be invalidated if the page with the link is changed. - Of Revision

  • @gmsantos well, I believe that the essential parts to the answer have been cited since it is not a very complex thing to transcribe, it seems that the author of the question is a person who is starting in programming and needs to learn to transcribe things into the code, just as it is in the job market, I did what I would like you to do with me if I had started by now.

-2

letrers = None    
for element for i:    
    letrers += f'{element}   
print(letrers)
  • It could complement the answer by explaining it?

  • Welcome to Stack Overflow in English. This code may be a solution to the question, but your answer might be better if you include an explanation of the key points of the code. The goal is not only to help those who asked the question, but the next visitors as well. Read more on Code-only answers - What to do?.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.