Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
print("\"text\" \"text\" \"text\" text text text text text text text text text\ntext text text text text text text")

Allow:

print("
  \"text\" \"text\" \"text\" text text text text \
  text text text text text\n
  text text text text text text text
  ")

// shorter alternative:
print("\"text\" \"text\" \"text\" text text text text \
  text text text text text\n
  text text text text text text text")

Extend to:

print("""
  "text" "text" "text" text text text text \
  text text text text text
  text text text text text text text
  """)

// shorter alternative:
print(""""text" "text" "text" text text text text \
  text text text text text
  text text text text text text text""")

Ban the following forms:

// #1
"
abc
def"

// #2
"abc
def
"

// #3
"""
abc
def"""

// #4
"""abc
def
"""

Trailing \ provides two functionalities:

  1. Hard wrapping a long line.
  2. Boundary for trailing whitespace characters.

(If no trailing whitespace character are presented, then we can ommit the \)

// #1
"
a\
b\
" == "ab"

// #1.1
"
a
b
" == "ab"

// #2
"
a \
b \
" == "a b "

// #3
"
 c \
 d \
" == " c  d "

// #3.1
" c  \
d " == " c  d "

// #3.2
" c  \
  d " == " c  d "

// #4
"""
a \
b 
c\
""" == "a b\nc"

// #4.1
"""
a \
b 
c
""" == "a b\nc"

// #5
"""
 a \
 b 
 c
""" == " a  b\n c"

// #5.1
""" a  \
 b 
 c""" == " a  b\n c"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.