Modify ad Delete the values of the dictionary keys-Remove items from the dictionary

 #Modify the values of the dictionary keys:

employee={"empid":101,"empname":"ramesh","salary":45000,"jobdesc":"developer"}

print(employee) #print all key values in dictionary

employee["jobdesc"]="Software"

print(employee)

employee.update({"compnayname":"google","address":"KPHB Colony"})

print(employee) #update more than one pair or item


#Remove items from the dictionary

pop(key[,d]) : Return and removes the item with the key and return its value. If the key is not found, it raises KeyError.

employee={"empid":101,"empname":"ramesh","salary":45000,"jobdesc":"developer"}

deleted_item=employee.popitem() #remove last inserted item from the dictionary

print(deleted_item) # print deleted item

print(employee) #print remaining itens in dictionay


# Remove key 'jobdesc' from the dictionary

deleted_item = employee.pop('jobdesc')

print(deleted_item)  

print(employee)


# remove all item (key-values) from dict

employee.clear()

print(employee)  


No comments:

Post a Comment

Latest Post

Don’t Sweat It – Chill with Crompton Air Cooler Deals

 ðŸŒž Don’t Sweat It – Chill with Crompton Air Cooler Deals  More Details : https://www.amazon.in/s?k=laptops+under+70000&crid=29QIFPXQYB3...