From cd4356d731e00c56487bcf463cf5560aeb6820fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20W=C3=B3jcik?= Date: Sun, 14 Jul 2024 20:05:18 +0200 Subject: [PATCH 1/3] Update delattr.md Added 2 examples of using delatrr() function --- docs/builtin/delattr.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/docs/builtin/delattr.md b/docs/builtin/delattr.md index e782f867..917293c3 100644 --- a/docs/builtin/delattr.md +++ b/docs/builtin/delattr.md @@ -16,6 +16,31 @@ Python delattr() built-in function +## Examples + +```python +# Example 1 +class Person: + def __init__(self, name, age): + self.name = name + self.age = age + +person = Person("John", 30) +delattr(person, 'age') +print(person.__dict__) # Output: {'name': 'John'} + +# Example 2 +class Car: + def __init__(self, make, model): + self.make = make + self.model = model + +car = Car("Toyota", "Corolla") +try: + delattr(car, 'year') +except AttributeError as e: + print(f"Error: {e}") # Output: Error: 'Car' object has no attribute 'year' +``` From 3cbba721bc0813a1165070a242f523a0e558fd22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20W=C3=B3jcik?= Date: Sun, 14 Jul 2024 23:09:56 +0200 Subject: [PATCH 2/3] Update delattr.md Fixed heading structure for added examples for delattr() --- docs/builtin/delattr.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/builtin/delattr.md b/docs/builtin/delattr.md index 917293c3..ce9f5bed 100644 --- a/docs/builtin/delattr.md +++ b/docs/builtin/delattr.md @@ -19,27 +19,27 @@ Python delattr() built-in function ## Examples ```python -# Example 1 class Person: def __init__(self, name, age): self.name = name self.age = age -person = Person("John", 30) -delattr(person, 'age') -print(person.__dict__) # Output: {'name': 'John'} +>>> person = Person("John", 30) +>>> delattr(person, 'age') +>>> person.__dict__ +# {'name': 'John'} -# Example 2 class Car: def __init__(self, make, model): self.make = make self.model = model -car = Car("Toyota", "Corolla") -try: - delattr(car, 'year') -except AttributeError as e: - print(f"Error: {e}") # Output: Error: 'Car' object has no attribute 'year' +>>> car = Car("Toyota", "Corolla") +>>> try: +... delattr(car, 'year') +... except AttributeError as e: +... print(f"Error: {e}") +# Error: 'Car' object has no attribute 'year' ``` From 10c70c24e75f0b1c3896b4dd6f3873d54b8013f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20W=C3=B3jcik?= Date: Sun, 14 Jul 2024 23:20:11 +0200 Subject: [PATCH 3/3] Update delattr.md deleted ## Example heading --- docs/builtin/delattr.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/builtin/delattr.md b/docs/builtin/delattr.md index ce9f5bed..d00ad9cb 100644 --- a/docs/builtin/delattr.md +++ b/docs/builtin/delattr.md @@ -16,8 +16,6 @@ Python delattr() built-in function -## Examples - ```python class Person: def __init__(self, name, age):