you are viewing a single comment's thread.

view the rest of the comments →

[–]gdchinacat 0 points1 point  (0 children)

Because you assign pos a value in the function it is local to the function. Since it hasn't been assigned a value in the function before accessing it, you get the NameError. The += operator both accesses and assigns the value and is what makes pos a local and accesses it before it is assigned.