From 6c1da6da5ef6dfad3aeb15669d48c600dcfafb02 Mon Sep 17 00:00:00 2001 From: "xuanyi.wang" Date: Fri, 7 Apr 2023 00:06:40 +0200 Subject: [PATCH] Update page 'Day 5 homework - Sloetjes' --- Day 5 homework - Sloetjes.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Day 5 homework - Sloetjes.md b/Day 5 homework - Sloetjes.md index ecc2375..df633ca 100644 --- a/Day 5 homework - Sloetjes.md +++ b/Day 5 homework - Sloetjes.md @@ -20,10 +20,24 @@ class Vault: if key != '_original_attrs' and self.__dict__ != self._original_attrs: print('Attribute deleted!') ``` -##### An example usage of the 'Vault' class: +##### An example usage of the Vault class: ``` v = Vault() print(v.treasure) # prints 'gold' v.x = 10 print(v.treasure) # prints 'Attribute deleted!\ngold' +``` +#### To get the other person's class to return "gold", despite any countermeasures they've implemented: +###### It can be achieved by creating a new class that inherits from the Vault class and overrides its _treasure attribute. +``` +class GoldVault(Vault): + def __init__(self): + super().__init__() + self._treasure = 'gold' +``` +###### Create a GoldVault object that inherits all methods and attributes from the Vault class and returns 'gold' as the value of the _treasure attribute: +``` +>>> gv = GoldVault() +>>> gv.treasure +'gold' ``` \ No newline at end of file