# Python Program illustrate how
# to overload an binary + operator
class A:
def __init__(self, a):
self.a = a
# adding two objects
def __add__(self, o):
return self.a + o.a
ob1 = A(1)
ob2 = A(2)
ob3 = A("Geeks")
ob4 = A("For")
print(ob1 + ob2)
print(ob3 + ob4)
str = "a" + "b"
array <~ str
fn int IntList.get(IntList* this, int idx) @operator([])
{
return this.vals[idx];
}
...
IntList x = ...
foo(x[1]);
f[x_Integer] := x^2;
f[x_String] := "not a number";
f[x_Symbol] := x^2;
Languages with Operator Overloading include C++, MATLAB, Python, PHP, R, Ruby, Perl, C#, Swift, Scala, Kotlin, Rust, Lua, Clojure, Haskell, Dart, Ada, D, Visual Basic .NET, Smalltalk, Groovy, F#, Speedie, C3, Eiffel, Ceylon, Io, Wolfram Language, Seed7, Perl 6, Object Pascal, FreeBASIC, Free Pascal
Languages without Operator Overloading include C, JavaScript, Java, Go, TypeScript, Visual Basic, Objective-C, Pascal, Modula-2, progsbase, BASIC, Jule
View all concepts with or missing a hasOperatorOverloading measurement