21
loading...
This website collects cookies to deliver better user experience
\
inside a string or characters that split into multiline."\"
is used to indicate the line continuation in Python. If any characters are found after the escape character, the Python interpreter will throw SyntaxError: unexpected character after line continuation character."\"
is used in Python to break up the code into multiline, thus enhancing the readability of the code.message = "This is really a long sentence " \
"and it needs to be split acorss mutliple lines " \
"to enhance readibility of the code"
print(message)
# Output
This is really a long sentence and it needs to be split acorss mutliple lines to enhance readibility of the code
\
as a division operator, which throws Syntax Error.# Simple division using incorrect division operator
a= 10
b=5
c= a\b
print(c)
# Output
File "c:\Projects\Tryouts\listindexerror.py", line 11
c= a\b
^
SyntaxError: unexpected character after line continuation character
\
* replace it with forward slash operator */
* as shown in the below code.# Simple division using correct division operator
a= 10
b=5
c= a/b
print(c)
# Output
2
\
* and if you add any character after the escaper character Python will throw a Syntax error.message = "This is line one \n" \+
"This is line two" \
"This is line three"
print(message)
# Output
File "c:\Projects\Tryouts\listindexerror.py", line 1
message = "This is line one \n" \+
^
SyntaxError: unexpected character after line continuation character
message = "This is line one \n" \
"This is line two \n" \
"This is line three"
print(message)
# Output
This is line one
This is line two
This is line three
"\n"
. If you append \n
, Python will treat it as an escape character and throws a syntax error.fruits = ["Apple","orange","Pineapple"]
for i in fruits:
print(i+\n)
# Output
File "c:\Projects\Tryouts\listindexerror.py", line 3
print(i+\n)
^
SyntaxError: unexpected character after line continuation character
\n
with "\n"
enclosed in the quotation marks properly.fruits = ["Apple","orange","Pineapple"]
for i in fruits:
print(i+"\n")