Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update 16_class_and_objects.py
I just replaced the NameError with the Attribute error.
  • Loading branch information
tahirpukhta authored Dec 19, 2023
commit 983789e01ee086ee0460db455c30db414969f74c
9 changes: 4 additions & 5 deletions Basics/Exercise/16_class_and_objects/16_class_and_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@ def display(self):
print(f"ID: {self.id} \nName: {self.name}")


# Creating a emp instance of Employee class
# Creating an emp instance of the Employee class
emp = Employee(1, "coder")

emp.display()
# Deleting the property of object
del emp.id
# Deleting the object itself
try:
print(emp.id)
except NameError:
except AttributeError:
print("emp.id is not defined")

# Deleting the object itself
del emp
try:
emp.display() # it will gives error after deleting emp
except NameError:
print("emp is not defined")
print("emp is not defined")