Single string print statements on multiple lines.

Discussion in 'Python' started by HeEm, Mar 12, 2007.

  1. HeEm

    HeEm Guest

    In my 100 level CS course, I was asked to create multiple lines of
    output within a single string. Of course I know how to:

    print "I am"
    print "a python"
    print "newbie."

    How can I get this accomplished using a single string (assuming this
    means a one line statement). Is there and escape character or
    something that could be added?

    Thanks for any help that can be provided.
    HeEm, Mar 12, 2007
    1. Advertisements

  2. The usual one: \


    "first line\nnextline"

    Diez B. Roggisch, Mar 12, 2007
    1. Advertisements

  3. HeEm

    MonkeeSage Guest

    If this is for a CS course, you shouldn't really be cheating and
    asking for an answer here, should you? I mean, the whole point of
    taking (and paying for!) a CS course is to learn CS, right? But like
    Diez said, the standard C escapes work in python: \t = TAB, \r =

    MonkeeSage, Mar 12, 2007
  4. HeEm

    Goldfish Guest

    Goldfish, Mar 12, 2007
  5. "Always go over old ground, re-inventing the wheel again and again" is the
    least efficient, most error-prone way of learning comp sci (or any other
    subject for that matter).

    There's a fuzzy line between "help me to learn this" and "do my work for
    me", but it is a real distinction. One of the distinguishing
    characteristics of an educated person and an ignoramus is that the
    educated person not only knows more stuff, but more importantly knows how
    to find out what he doesn't already know. That can include looking it up
    in a reference book or asking somebody who does know.
    Steven D'Aprano, Mar 13, 2007
  6. Goldfish a écrit :
    Given the way the question was expressed, I don't think this particular
    rule applies here. Obviously, the OP is not trying to cheat (explicitelt
    aknowledging it is homework), and has a good enough understanding of
    what the usual solution is (asking for the escape char in Python).

    Now of course the answer is in the FineManual(tm), which implies that
    either the OP failed to read it, or that the FineManual is not so fine -
    but that's another problem.

    My 2 cents...
    Bruno Desthuilliers, Mar 13, 2007
  7. En Tue, 13 Mar 2007 08:31:17 -0300, Bruno Desthuilliers
    If the FineManual(tm) is the Tutorial, it only explain escape sequences
    minimally, presuming some prior knowledge on the reader. For users with
    previous experience in different languages (like VB or Delphi) using \n is
    rather strange.
    Gabriel Genellina, Mar 13, 2007
  8. No, the tutorial is aimed at /introducing/ the concept of escape
    sequence <G>

    There are also the Language Reference Manual, and the Library
    Reference Manual.

    These are where the detailed information will be found.
    Wulfraed Dennis Lee Bieber KD6MOG

    (Bestiaria Support Staff: )
    Dennis Lee Bieber, Mar 14, 2007
    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.