简体   繁体   中英

Python IDLE shell - How to make multiline strings

ANSWERED (But if for some reason you want to read it you can)


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!'

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM