Skip to content

Instantly share code, notes, and snippets.

@SureshKL
Created December 11, 2018 12:09
Show Gist options
  • Save SureshKL/ab2d183bb217adc19824dbb0ff374444 to your computer and use it in GitHub Desktop.
Save SureshKL/ab2d183bb217adc19824dbb0ff374444 to your computer and use it in GitHub Desktop.
Demonstrating method overriding by custom list concatenation
class ListAddition:
def __init__(self, numbers):
self.x = numbers
def __add__(self, other):
return [self.x, other.x]
x = ListAddition([1, 2, 3])
y = ListAddition([4, 5, 6])
print(x + y)
# Output: [[1,2,3], [4,5,6]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment