How to solve unexpected eof while parsing error in python
Posted on: May 31, 2021 by Deven
In this article, you will learn how to solve unexpected eof while parsing error in python.
Let’s look at a code example that produces the same error.
fruits = ["mango", "pineapple", "grapes", "banana"]
for i in fruits:
In the code snippet above we haven’t added any code into our for
loop which will throw the error below.
Output
File "<string>", line 2
for i in fruits:
^
SyntaxError: unexpected EOF while parsing
In Order to solve this problem, we need to add code in the loop for this example we can add print()
statement like below:
fruits = ["mango", "pineapple", "grapes", "banana"]
for i in fruits:
print(i)
Output
mango
pineapple
grapes
banana
Please also note that an “unexpected EOF while parsing” error can also occur when you forget to close all of the parenthesis on a line of code, you may consider double-checking parenthesis before executing the code.
Share on social media
//