Python Dictionaries

 



Dictionaries are *Mutable unordered collections with elements in the form of a key:value pair that associates key to value. Dictionaries in python are enclosed with in curly braces ( {} ).

syntax:--
dict={ key : value }

for eg:- dict={ "name" : "EDUshark", "marks" : 100  } 

here name and marks enclosed within inverted commas are acting as key whereas edushark and 100 are their values. That combine together and make key : value pair. 

 

A dictionaries operation that takes a key and finds the corresponding value is called LOOK UP


 







Another way to create dictionaries,

dict = { "name" : [ 'harry','sha','hp' ], "marks" : [ 55,32,15 ] }

suppose you want to add "EDUshark" inplace of "sha".

then, write   dict[ 'sha' ] = "EDUshark"

YOU can add dictionaries in loop, conditional statements, or while working with mysql-connector, etc...

Comments