Skip to content

Commit 75058c8

Browse files
committed
TR updates, first round
1 parent a30d1ac commit 75058c8

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

python-mutable-immutable/immutable.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Immutable:
2-
def __init__(self, value):
3-
super().__setattr__("value", value)
2+
def __init__(self, magnitude):
3+
super().__setattr__("magnitude", magnitude)
44

55
def __setattr__(self, name, value):
66
raise AttributeError(f"can't set attribute '{name}'")

python-mutable-immutable/person.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Person:
2+
def __init__(self, name):
3+
self.name = name
4+
5+
6+
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+
print(type(john))

0 commit comments

Comments
 (0)