1#print keys and values from the dictionary
2
3for k, v in dic.items():
4 print(k, v)
1#title : Dictionary Example
2#author : Joyiscold
3#date : 2020-02-01
4#====================================================
5
6thisdict = {
7 "brand": "Ford",
8 "model": "Mustang",
9 "year": 1964
10}
11
12#Assigning a value
13thisdict["year"] = 2018
1student_data = {
2 "name":"inderpaal",
3 "age":21,
4 "course":['Bsc', 'Computer Science']
5}
6
7#the keys are the left hand side and the values are the right hand side
8#to print data you do print(name_of_dictionary['key_name'])
9
10print(student_data['name']) # will print 'inderpaal'
11print(student_data['age']) # will print 21
12print(student_data['course'])[0]
13#this will print 'Bsc' since that field is an array and array[0] is 'Bsc'
1# Dictionaries in Python are used to store set of data like Key: Value pair
2
3# the syntax of a dictionary in Python is very simple we use {} inside that
4 # we define {Key: Value}, to separate multiple values we use','
5programming_dictionary = {
6 "Bug": "An error in a program that prevents the program from running as expected.",
7
8 "Function": "A piece of code that you can easily call over and over again.",
9
10 "Loop": "The action of doing sommething again and again",
11}
12# to retrieve the values from a dictionary we use the Key name as an Index
13# retrieving the Function's definition
14print(programming_dictionary["Function"]) # this will print the definition of Function
15
16# if you wanna print all the entries in the dictionary you can do that by for loop
17for key in programming_dictionary:
18 print(programming_dictionary[key]) # prints all entries
19
20# adding items to a dictionary
21# the following code will add another entry to the dictionary called Variable
22programming_dictionary["Variable"] = "The label to store some sort of data"
23print(programming_dictionary["Variable"])
24
25# editing the values of a key
26# editing the value of variable
27programming_dictionary["Variable"] = "Variables are nothing but reserved memory locations to store values. This means that when you create a variableyou reserve some space in memory"
28
29# if you learnt something from this please upvote it
30
1#dictionary
2programming = {
3 "Bugs": "These are the places of code which dose not let your program run successfully"
4 ,"Functions":"This is a block in which you put a peice of code"
5 ,"shell":"This is a place where the code is exicuted"
6 }
7print(programming["Bugs"])
8print(programming["shell"])
9#error
10#print(programming["pugs"])
1thisdict = {
2 "key1" : "value1"
3 "key2" : "value2"
4 "key3" : "value3"
5 "key4" : "value4"
6}