Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Abraxas Group Title

Who knows how to print in a single line the result of a for loop statement in Python3? In Python 2 we can print the content of a list in a unique line like this: >>> A = list(range(3)) >>> A [0, 1, 2] >>> for i in A: print i 0 1 2 >>> for i in A: print i, 0 1 2 ## but if we try to print the same function in ## Python3 it displays another thing >>> for i in A: print (i), 0 (None,) 1 (None,) 2 (None,) ## Thank a lot for your help!!!

  • one year ago
  • one year ago

  • This Question is Closed
  1. andrew.m.higgs Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Try print (i,) I dont have Python 3 but the doc looks as though this should work. Hope this helps.

    • one year ago
  2. Abraxas Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Nop. it doesn't work either. :( Thank anyway!

    • one year ago
  3. Abraxas Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    The help only says: print( . . . ) print(value, ..., sep=' ', end='/n', file=sys.stdout) optional keyword arguments: file: ..bla bla bla.. sep: string inserted between values, default a space. end: string appended after the last velue, default a new line. I tested with both but nothing. : (

    • one year ago
  4. andrew.m.higgs Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    l = (1, 2, 3, 4, 5) for i in l: print (i, end=' ')

    • one year ago
  5. andrew.m.higgs Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    The default value for end is a new line char. Replace it with a space and you get the result you want.

    • one year ago
  6. Abraxas Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Sí!!!!!!!! Gracias!!!!!

    • one year ago
  7. andrew.m.higgs Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    :-) Glad I could help.

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.