repl.it
@lclarkejhdf/

Problem with getters

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class test:
  def __init__(self, attr):
    self.attr = attr
  
  def getAttr(self):
    return self.attr
  
  def setAttr(self, newAttr):
    self.attr = newAttr

t1 = test([1,2,3])

lst = t1.getAttr()
print("List 1:",lst)
lst.append(4)
print("List 2:",lst)
lst = []
newlst = t1.getAttr()
print("List 3:",newlst)
print("\nList 3 should be just [1,2,3], but the append performed on the variable has been performed on the attribute.")