syntaxerror: EOL while scanning string literal

Cause of syntaxerror: EOL while scanning string literal

This is a very common error called syntaxerror: EOL while scanning string literal in the Python programming language. This error mainly occurred while dealing with the end of the line in a file or in any string. Basically, this error arises in python when the user does not write the string in the correct format while writing any code. The most common mistakes are correct placement of “” while entering any string object in python. An example of the above error is shown in the string below: 

 

s1=”study experts is an online learning platform…………” 

 

This line will show an error in python due to the incorrect placement of “” in the string. The error looks like as shown in the image:

 

 

 

Solution

To solve this error one of the easiest solutions is to use  “”” while declaring any string object. An example of the same is:

 

s1 = “”” study experts is an online learning platform…..”””

 

Another reason is that the user added characters to the string, which is the cause. If you possess any of them, simply “escape” them using, and everything should be alright.

Apart from all this one can also write r just at the start of the string in python. r stands for treating the string as a raw string. See “String literals” in the official Python 2 Reference: A character that comes after a backslash in a string is included without change when an “r” or “R” prefix is present, and all backslashes are left in the string. An example of the above concept is shown below:

 

s1 = r’study experts is an online learning platform….’

 

 

Also Read: add text editor in HTML form Codeigniter

 

 

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *