How avoid both a newline and a space between 2 print commands?

Discussion in 'Python' started by seberino, Jan 23, 2008.

  1. seberino

    seberino Guest

    print "foo"
    print "bar"

    has a newline in between "foo" and "bar"

    print "foo",
    print "bar"

    has a space in between "foo" and "bar"

    How prevent ANYTHING from going in between "foo" and "bar" ??

    (Without defining a string variable.)

    Chris
     
    seberino, Jan 23, 2008
    #1
    1. Advertisements

  2. sys.stdout.write("foo")
    sys.stdout.write("bar")

    Diez
     
    Diez B. Roggisch, Jan 23, 2008
    #2
    1. Advertisements

  3. seberino

    Mike Kent Guest

    print "%s%s" % ("foo", "bar") ## If "%s%s" doesn't violate your
    condition of not defining a string variable, I'm not sure.
     
    Mike Kent, Jan 23, 2008
    #3
  4. seberino

    seberino Guest

    Diez

    Thanks. Beautiful! I <3 Python!

    Chris
     
    seberino, Jan 23, 2008
    #4
  5. seberino

    Ben Finney Guest

    Even better, this form will survive unchanged into Python 3, whereas
    the 'print' statement will undergo some changes in syntax and
    perhaps semantics.
     
    Ben Finney, Jan 23, 2008
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.