Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created Jul 2, 2020
Embed
What would you like to do?
#Adding two numbers
a1=4+5
#When we use + operator, __add__() magic method is invoked automatically
a2=(4).__add__(5)
print (a1)#Output:9
print (a2)
#concatenating two strings
s1="Hello " + "world!"
s2="Hello ".__add__("world!")
print (s1)#Output:Hello world!
print (s2) #Output:Hello world!
#merging two lists
l1=[1,2]+[3,4]
l2=[1,2].__add__([3,4])
print (l1)#Output:[1, 2, 3, 4]
print (l2)#Output:[1, 2, 3, 4]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment