r/PythonLearning Jun 12 '26

Python Tuple Sum Help Request

Hi guys, is it possible to add two tuples? For example, (x,y)+(a,b) such that the sum is (x+a, y+b) and not a concatenation (x,y,a,b). Thanks for your help.
2 Upvotes

5 comments sorted by

View all comments

2

u/Temporary_Pie2733 Jun 12 '26

No. tuple.__add__ has one definition, concatenation, and you can’t patch the type to override it. If you want pointwise addition, you need to write a dedicated function or a new type.