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

How to Generate Barcode and QR code For Our Products

 మీ products కి barcode / QR code generate చేయాలంటే OPTION 1: ONLINE (No Coding – Quick) Best for small shops / beginners 👉Free websites: T...