We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a30d1ac commit 75058c8Copy full SHA for 75058c8
python-mutable-immutable/immutable.py
@@ -1,6 +1,6 @@
1
class Immutable:
2
- def __init__(self, value):
3
- super().__setattr__("value", value)
+ def __init__(self, magnitude):
+ super().__setattr__("magnitude", magnitude)
4
5
def __setattr__(self, name, value):
6
raise AttributeError(f"can't set attribute '{name}'")
python-mutable-immutable/person.py
@@ -0,0 +1,17 @@
+class Person:
+ def __init__(self, name):
+ self.name = name
+
+class Student(Person):
7
+ def __init__(self, name, major):
8
+ super().__init__(name)
9
+ self.major = major
10
11
12
+john = Student("John", "Computer Science")
13
+print(type(john))
14
+john.__class__ = Person
15
+print(john.name)
16
+print(john.major)
17
0 commit comments