I was trying the make a function in python and using a for loop to iterate all keys or values from a dictionary and I was trying to assign a global variable inside the function so I can print the keys outside the function but it was only printing the last key:
ships = {
'playerShip1' : cv.imread(r'C:\\Users\\a\\Desktop\\desktopFolders\\pyexample\\seafightShip.jpg', cv.IMREAD_UNCHANGED),
'playership2' : cv.imread(r'C:\\Users\\a\\Desktop\\desktopFolders\\pyexample\\seafightCroped.jpg', cv.IMREAD_UNCHANGED)
}
def att():
global key
for key in ships:
global shipLoc
shipLoc = key
#it works okay here
#print(key)
att()
#quit()
#but it only prints the last key here
print(key)
quit()