using del keywords

Deleting elements using del keywords:

Employee = {"Name": "John", "Age": 29, "salary":25000,"Company":"GOOGLE"} 
print(type(Employee)) 
print("printing Employee data .... ") 
print(Employee) 
print("Deleting some of the employee data") 
del Employee["Name"] 
del Employee["Company"] 
print("printing the modified information ") 
print(Employee) 
print("Deleting the dictionary: Employee"); 
del Employee 
print("Lets try to print it again "); 
print(Employee) 
 
Output:
<class 'dict'>
printing Employee data .... 
{'Age': 29, 'Company': 'GOOGLE', 'Name': 'John', 'salary': 25000}
Deleting some of the employee data
printing the modified information 
{'Age': 29, 'salary': 25000}
Deleting the dictionary: Employee
Lets try to print it again 
Traceback (most recent call last):
  File "list.py", line 13, in <module>
    print(Employee)
NameError: name 'Employee' is not defined
Translate »