I define an append () method and an extend () method for a class object. It appends myList to the member and expands the myList member accordingly.
global globalList globalList = [] class MyList(): def __init__(self): self._myList = [1, 2, 3] @property def myList(self): return self._myList + globalList @myList.setter def myList(self, val): self._myList = val def append(self, val): self.myList = self.myList + [val] return self.myList def extend(self, val): return self.myList.extend(val) mL1 = MyList() print("myList: ", mL1.myList) mL1.append(4) print("after appending a 4, myList: ", mL1.myList) mL1.myList.extend([5,6,"eight","IX"]) print("after extend, myList: ", mL1.myList)
result
>>> ('myList: ', [1, 2, 3]) ('after appending a 4, myList: ', [1, 2, 3, 4]) ('after extend, myList: ', [1, 2, 3, 4, 5, 6, 'eight', 'IX'])
source share