Here is sample program illustrating scoping in Python.
Larry and Curly are walking merrily together. Suddenly, Moe sees his friends from a distance and starts running towards them. Just as Moe finally catches up with Larry and Curly, he goes out of scope and disappears from the screen. If you want for him to keep up with his friends, you need to remove three # symbols.
Larry = UsedRobot(colour='blue') Curly = UsedRobot(1, 3, colour='green') for i in range(3): Larry.move() Curly.move() def wait_for_me(): #global Moe Moe = UsedRobot(1, 2, colour='yellow') for i in range(3): Moe.move() Larry.move() Moe.move() Curly.move() wait_for_me() # first image below; Moe is there. Larry.move() # second image below; Moe is gone. Curly.move() #Moe.move() Larry.move() Curly.move() #Moe.move() Larry.turn_off()