print values of dictionary python code example

Example 1: printing python dictionary values

#print keys and values from the dictionary

for k, v in dic.items():
  print(k, v)

Example 2: printing dictionary in python

mydict = {'score1': 41,'score2': 23}
mydict['score3'] = 45

# key value pairs
for i in mydict:
    print(i,mydict[i])

Example 3: how to print all elements of a dictionary in python

# you can also use items method

my_dict = {"one": 1,"two":2,"three":3,"four":4}

for key,value in my_dict.items():
    print("Key : {} , Value : {}".format(key,value))

Example 4: python dictionary

#title			:Dictionary Example
#author         :Josh Cogburn
#date           :20191127
#github         :https://github.com/josh-cogburn
#====================================================

thisdict = {
	"brand": "Ford",
 	"model": "Mustang",
 	"year": 1964
}

#Assigning a value
thisdict["year"] = 2018

Example 5: how to print a value from a dictionary in python

dictionary={
  
    "Jeff":{
      	"lastname":"bobson",
        "age":55,
        "working":True
    },
  
    "James":{
      	"lastname":"Bobson",
        "age":34,
        "working":False
    }
}

# For a good format:

for i in dictionary:
    print(i, ":")
    for j in dictionary[i]:
        print("  ", j, ":", dictionary[i][j])
    print()
        

# Output:

Jeff :
   lastname : bobson
   age : 55
   working : True
   
James :
   lastname : Bobson
   age : 34
   working : False
    
# For just a quick reading:

for k, v in dictionary.items():
  print(k, v)
  
# Output: 

Jeff {'lastname': 'bobson', 'age': 55, 'working': True}
James {'lastname': 'Bobson', 'age': 34, 'working': False}