banovski

Operator overloading

Apr 20th, 2022 (edited)
944
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.24 KB | None | 0 0
  1. class MyList:
  2.     def __init__(self, list):
  3.         self.list = list
  4.  
  5.     def __sub__(self, arg):
  6.         self.list.remove(arg)
  7.         return self.list
  8.  
  9. myList = MyList([1, 2, 3])
  10. print(myList - 2)
  11.  
  12. # результат -- [1, 3]
  13.  
Add Comment
Please, Sign In to add comment