0

what happens to the array generated by python 2.X range() function at the end of loop ?

Is the array deleted immediately or its present till the scope of respective function

1
  • 1
    If what you mean is when you do for x in range(...): then yes it is garbage collected after the loop since its reference count is 0. Commented Jun 9, 2018 at 2:19

1 Answer 1

1

Warning: For-loop variables “leaking” into the global namespace

In contrast to some other programming languages, for-loops will use the scope they exist in and leave their defined loop-variable behind.

http://sebastianraschka.com/Articles/2014_python_scope_and_namespaces.html#warning-for-loop-variables-leaking-into-the-global-namespace

So, for example, number in : for number in range(0,5) will still be accessible after the loop (and will have the last value it was given.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.