You are using outdated bytecode, restart Python.
Python compiles the source code into bytecode and interprets it. This means that the interpreter does not work with the source code after compilation.
However, we humans cannot read the bytecode very well, so when there is an exception and the interpreter wants us to understand where everything went wrong, he would like to show you the source code again. Thus, the source code is loaded on demand when the trace is displayed, and the lines are taken from the source code based on the information recorded using the bytecode.
In your case, you are using a bytecode that uses the name xrange . But you have already adjusted the source code to use range . The bytecode throws an exception, and Python loads the source code from disk and shows the corrected source code .
The solution is to tell Python to recompile the source code by restarting it. If restarting does not help, Python determines that the source code is older than the bytecode it cached. Delete the __pycache__ directory next to the source code to clear the bytecode cache, and delete any .pyc file that might be in the same directory as your source.
Note that you can refuse to call list() ; You do not need to have a list for the for loop to work; for j in range(epoch): working fine.
source share