. Advertisement .
..3..
. Advertisement .
..4..
While running the program, I got this error ”Syntaxerror: unexpected eof while parsing python”. This error happens when I define the list in a Python file called eof_for.py and use a for . loop
Here is the detail of my code:
fruits = 'mango', 'apple', 'kiwi', 'banana'
for fruit in fruits:
Here is the the detail of the error I got:
$ python eof_for.py
File "eof_for.py", line 4
^
SyntaxError: unexpected EOF while parsing
I have tried several workarounds, but they still do not get the desired results. If you have come across this situation and have a solution for this error, please let me know.
The cause: This is a syntax error that when you build a
for
loop to go through the elements of a list but don’t finish the body of the loop, you will get this error.The solution: You must add a body to the
for
loop to avoid the ”Syntaxerror: unexpected eof while parsing python”. For instance, consider a single line that prints the list’s elements: