def main(): lib = {} ### THIS IS WHERE lib IS DECLARED/DEFINED book1 = {'name':'Alice','author':'Lewis'} book2 = {'name':'Rainbow','author':'Clancy'} lib['ID1'] = book1 lib['ID2'] = book2 passInteger = 0 ############# START FOR LOOP ################ for libKey in lib: ### <---- THIS IS WHERE libKey is defined each time the loop runs passInteger = passInteger + 1 passString = str(passInteger) print("///////// Pass " + passString + " //////////") print("This variable is the libkey, it changes every pass:") print(libKey) print("") print("This is the libKey put into the lib to return a specific book:") print(lib[libKey]) print("") print("This is the entire library, it " + "shouldn't change with any pass because " + "the only variable that changes with each pass " + "is libKey and that's not used here:") print(lib) print("") print("") print("///////// END PASS" + passString + "/////////") print("") ############ END FOR LOOP ############### print('do you understand why each print command printed what it printed?') main()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question