+ 2
I fail to understand
the order in which a key:value appears/displayed in a dictionary. for example. squares = {1: 1, 2: 4, 3: "error", 4: 16,} squares[8] = 64 squares[3] = 9 print(squares). here suppose i add squares [9]=81. where will it appear in the output. will it appear in the beginning at the last. or will it appear randomly in the output. plis help
4 Antworten
+ 3
Also that finds the square of a number too:
num=input('Enter a number to calculate it's square: ')
square=num**2
print(square)
+ 3
It will appear in 10th element
+ 2
In Python, the order in a dictionary is NEVER guaranteed, so you can never be sure it will appear where you expect it to.
+ 1
Dictionaries are unrodered collections. So the ordre is not important and it is not guaranted where the elements appear in your dictionary.