Internal Operations Occurring During a Python Loop

I know that from some testing below, the code snippet works as intended, but I want to know what is happening on the python server here.

for c in curr.getChildren():
  if point in c:
    change = True
    curr = c

for example with a toy:

x = [1,2,3]
for c in x:
  print ('hi')
  if c == 2:
    x = 2

The print statement is triggered three times, and x is reassigned to 2. Whether python internally represents the container as a deep copy somewhere or is an iterator simply connected essentially to the memory cell of that container. It is safe? In general, it is curious what is happening here behind the scenes.

+4
source share
1 answer

Python (x) , (c). , .

, .

docs.python.org

github.com/python/cpython

, , for. , , for ( ) , ( ).

+2

All Articles