pythonpython-idle

Python IDLE shell - How to make multiline strings


I am a beginner at Python and I know how to type the correct syntax but when I repeat it, it comes out with no extra lines, it just says "\n"

Details on example below

My variable is fred and I set it to what it says below, and then on the 3rd line I made it print the text. Please tell me if I didn't describe it correctly, keep in mind I'm a beginner.

Example

>>> fred = '''How do dinosaurs pay their bills?
With tyrannosaurus checks!'''
>>> fred
'How do dinosaurs pay their bills?\nWith tyrannosaurus checks!'

I use Python 3.4.2 (shell) on Windows 7 64-bit.


Solution

  • The \n in that string represents the new line symbol. For pretty much all purposes, it is a new line.

    What you're doing is correct.

    To print the lines on separate lines:

    for line in jack.split("\n"):
        print(line)