Created
December 11, 2018 12:09
-
-
Save SureshKL/ab2d183bb217adc19824dbb0ff374444 to your computer and use it in GitHub Desktop.
Demonstrating method overriding by custom list concatenation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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