In Python, the loop variable of a for loop is an ordinary variable in the surrounding scope. It does not disappear when the loop ends. After the loop, it still holds the last value it was assigned. Many other languages treat loop variables as local to the loop, so this is a favourite PCEP trap, and questions often print the variable right after the loop. Nothing resets or deletes it for you.
Keep reading for free
Create a free StudyToCert account to read the rest of this lesson: 7 more sections, 5 key terms, a real-world example, an exam tip and self-check questions. Every lesson, lab and practice test is free with an account.