28
loading...
This website collects cookies to deliver better user experience
"
), which needs to be closed at the end of the line.def getName():
print("My name is Chandler Bing)
getName()
# Output
File "c:\Projects\Tryouts\listindexerror.py", line 2
return "My name is Chandler Bing
^
SyntaxError: EOL while scanning string literal
def getName():
print("My name is Chandler Bing")
getName()
# Output
My name is Chandler Bing
def getMessage():
message= "This is Chandler Bing and i am one of the famous actor in the
TV Series called Friends. Welcome to My world"
print(message)
getMessage()
# Output
File "c:\Projects\Tryouts\listindexerror.py", line 2
message= "This is Chandler Bing and i am one of the famous actor in the
^
SyntaxError: EOL while scanning string literal
(''' Hello ''')
* marks or 3 double quotation (""" Hello """)
marks to resolve the issue. \n
to split wherever required into multi-line.def getMessage():
message= """This is Chandler Bing and i am one of the famous actor in the
TV Series called Friends. Welcome to My world"""
print(message)
getMessage()
# Output
This is Chandler Bing and i am one of the famous actor in the
TV Series called Friends. Welcome to My world
'
) to open a string, do use single quotes ('
) to close a string.def getMessage():
message= "Hello World'
print(message)
getMessage()
# Output
File "c:\Projects\Tryouts\listindexerror.py", line 2
message= "Hello World'
^
SyntaxError: EOL while scanning string literal
"
)* to match the beginning of the string will resolve the issue here.def getMessage():
message= "Hello World"
print(message)
getMessage()
# Output
Hello World
(\)
* as an escape sequence. So, in this case, it will treat both (\")
as a single character, and according to Python, the string is not enclosed properly.# Storing a directory path
folderPath= "C:\Program Files\Python\"
print(folderPath)
# Output
File "c:\Projects\Tryouts\listindexerror.py", line 2
folderPath= "C:\Program Files\Python\"
^
SyntaxError: EOL while scanning string literal
# Storing a directory path
folderPath= "C:\\Program Files\\Python\\"
print(folderPath)
# Output
C:\Program Files\Python\