Python Forum
Do I always have to use triple quotes or \n for multi-line statements?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Do I always have to use triple quotes or \n for multi-line statements?
#1
Which multi-line statements do not require me to use triple quotes or \n? I am new to Python. Thanks for answering.
Reply
#2
You can also use parenthesis/brackets/braces to imply line continuation (start a multi line)
var = (
    'some long string'
    'that just keeps going'
    'and going'
)
Output:
some long stringthat just keeps goingand going
Dont add commas otherwise you created a tuple.
Quote:
Output:
('some long string', 'that just keeps goingand going') ('some long string', 'that just keeps going', 'and going')

To be more complete there is also backslash
var = 'some long string' \
    'that just keeps going' \
    'and going'
I still prefer triple quotes though because then you dont need quotes on each line which could be add or removed at any time making more work. Also it is less keystrokes. I also hate the appearance of backslash.
Recommended Tutorials:
Reply
#3
Thanks for answering. I was wondering, are there any multi-line statements that do not require the use of triple quotes or \n?
Reply
#4
that is multi-line statements without using triple quotes or newline characters.
Recommended Tutorials:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to add multi-line comment section? Winfried 1 241 Mar-24-2024, 04:34 PM
Last Post: deanhystad
  regex multi-line kucingkembar 6 1,621 Aug-27-2022, 10:27 PM
Last Post: kucingkembar
  multi-line CMD in one-line python kucingkembar 5 4,072 Jan-01-2022, 12:45 PM
Last Post: kucingkembar
  Two types of single quotes Led_Zeppelin 2 1,943 Mar-15-2021, 07:55 PM
Last Post: BashBedlam
  Multi-line console input lizze 4 2,409 Dec-26-2020, 08:10 AM
Last Post: lizze
  Quotes vs. no quotes around numbers Mark17 6 3,177 Aug-06-2020, 04:13 AM
Last Post: t4keheart
  EOF while scanning triple-quoted string literal louis216 1 3,974 Jun-30-2020, 04:11 AM
Last Post: bowlofred
  Python convert multi line into single line formatted string karthidec 2 9,518 Dec-23-2019, 12:46 PM
Last Post: karthidec
  Help converting MATLAB triple-for loop to Python davlovsky 1 2,010 Oct-29-2019, 10:26 PM
Last Post: scidam
  multi-line messages in raised exceptions? Skaperen 3 7,405 Aug-01-2019, 02:17 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020