0
Can somebody please explain this code?
class List(list): def __matmul__(self,other): newlist = List() for k in range(len(other)): newlist.append(self[k]+other[k]) return newlist l1 = List((1,2,3,4,5)) l2=List((9,8,7,6,5)) l3= l1 @ l2 print(sum(l3)) Output: 50
4 Réponses
+ 1
Shantanu
Here we are adding two list so final list is
[10, 10, 10, 10, 10]
And sum of this list is 50
+ 1
Shantanu
Role of '@' depends on magic method __matmul__
if you change this method then '@' will not work.
0
A͢J , what is the role of "@" in the line >> l3 = l1 @ l2?
0
Magic or Dunder Methods in Python
https://www.tutorialsteacher.com/python/magic-methods-in-python