+ 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

5th Mar 2017, 8:06 PM
stephen haokip
stephen haokip - avatar
4 odpowiedzi
+ 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)
5th Mar 2017, 8:11 PM
Ali Emir Kızıl
Ali Emir Kızıl - avatar
+ 3
It will appear in 10th element
5th Mar 2017, 8:13 PM
Ali Emir Kızıl
Ali Emir Kızıl - avatar
+ 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.
5th Mar 2017, 10:42 PM
Amaras A
Amaras A - avatar
+ 1
Dictionaries are unrodered collections. So the ordre is not important and it is not guaranted where the elements appear in your dictionary.
6th Mar 2017, 12:30 AM
Abdelkader Ait Assou
Abdelkader Ait Assou - avatar