overloading the + operator outside of a class
Is this sort of thing possible (see code below) . More interested in the overloading part rather than just the ability to add the list together. (I've done something similar C++ no problem) def __add__(self, obj): temp = [] temp[0] = self[0] + obj[0] temp[1] = self[1] + obj[1] return temp list1 = [10, 10] list2 = [10, 10] print(list1 + list2) # want output to be [20, 20] here a simple example but in c++: #include <iostream> using namespace std; class person{ public: int intA; int intB; person(int a, int b){ intA = a; intB = b; } }; //########################### int operator+(int total, person &obj){ //## <-how do you do this sort of thing? return total + obj.intA + obj.intB; } //########################## int main() { person rod(20, 20); int a = 20 + rod; cout << a << endl; return 0; }