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

29th Oct 2022, 8:09 AM
Shantanu
Shantanu - avatar
4 Answers
+ 1
Shantanu Here we are adding two list so final list is [10, 10, 10, 10, 10] And sum of this list is 50
29th Oct 2022, 8:21 AM
A͢J
A͢J - avatar
+ 1
Shantanu Role of '@' depends on magic method __matmul__ if you change this method then '@' will not work.
29th Oct 2022, 10:00 AM
A͢J
A͢J - avatar
0
A͢J , what is the role of "@" in the line >> l3 = l1 @ l2?
29th Oct 2022, 8:23 AM
Shantanu
Shantanu - avatar
29th Oct 2022, 9:05 AM
SoloProg
SoloProg - avatar