0
kanye_quote = """My greatest pain\
 in life is that I will never be able to see myself perform live"""

I am trying to create a line break but not having any luck. I am using the """ method to allow for multiple lines. It was my understanding that \ would create a new line but when I run the script, I am not getting a new line. Any Help would be terrific in solving this little problem.

4
  • You may use "Line1\nLine2" or remove the \ in your string literal - see ideone.com/lkrkoS Commented Aug 20, 2016 at 13:17
  • that works, so the backslash by itself does nothing? Commented Aug 20, 2016 at 13:20
  • If you are using the """ or ''' then a \ won't work. Since it basically tells python continue on the next line from here. With the triple you can just go to a new line ( press enter ). If it is a normal string then add\n where you want a new line. Commented Aug 20, 2016 at 13:21
  • got it, thanks everyone for the clarification, I am a beginner Commented Aug 20, 2016 at 13:24

1 Answer 1

2

If you remove the \ you got a line break. The \ is telling python to ignore the line break. The triple quote method lets you enter string on multiple lines. If you want to enter the string on one line you can use \n to get line breaks.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.