{"id":1722,"date":"2018-09-03T17:27:35","date_gmt":"2018-09-03T10:27:35","guid":{"rendered":"http:\/\/www.booboohome.com\/blogs\/?p=1722"},"modified":"2025-08-10T15:51:35","modified_gmt":"2025-08-10T08:51:35","slug":"python-operator-overloading","status":"publish","type":"post","link":"https:\/\/www.booboohome.com\/blogs\/2018\/09\/python-operator-overloading\/","title":{"rendered":"Python &#8211; Operator Overloading"},"content":{"rendered":"<p><strong>operator overloading<\/strong><br \/>\n\u0e15\u0e31\u0e27\u0e14\u0e33\u0e40\u0e19\u0e34\u0e19\u0e01\u0e32\u0e23(operator) \u0e17\u0e33\u0e07\u0e32\u0e19\u0e01\u0e31\u0e1a built-in class \u0e41\u0e15\u0e48\u0e17\u0e33\u0e07\u0e32\u0e19\u0e41\u0e15\u0e01\u0e15\u0e48\u0e32\u0e07\u0e01\u0e31\u0e19\u0e15\u0e32\u0e21\u0e0a\u0e19\u0e34\u0e14\u0e02\u0e2d\u0e07\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25 \u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e40\u0e0a\u0e48\u0e19 \u0e15\u0e31\u0e27\u0e14\u0e33\u0e40\u0e19\u0e34\u0e19\u0e01\u0e32\u0e23 &#8220;+&#8221; \u0e08\u0e30\u0e14\u0e33\u0e40\u0e19\u0e34\u0e19\u0e01\u0e32\u0e23\u0e40\u0e1e\u0e37\u0e48\u0e2d\u0e1a\u0e27\u0e01\u0e08\u0e33\u0e19\u0e27\u0e19 2 \u0e08\u0e33\u0e19\u0e27\u0e19 \u0e2b\u0e23\u0e37\u0e2d \u0e2d\u0e32\u0e08\u0e08\u0e30\u0e43\u0e0a\u0e49\u0e40\u0e1e\u0e37\u0e48\u0e2d\u0e17\u0e33\u0e01\u0e32\u0e23\u0e40\u0e0a\u0e37\u0e48\u0e2d\u0e21\u0e02\u0e49\u0e2d\u0e04\u0e27\u0e32\u0e21 2 \u0e02\u0e49\u0e2d\u0e04\u0e27\u0e32\u0e21\u0e01\u0e47\u0e44\u0e14\u0e49 \u0e04\u0e38\u0e13\u0e25\u0e31\u0e01\u0e29\u0e13\u0e30\u0e40\u0e0a\u0e48\u0e19\u0e19\u0e35\u0e49 \u0e0b\u0e36\u0e48\u0e07\u0e2d\u0e19\u0e38\u0e0d\u0e32\u0e15\u0e34\u0e43\u0e2b\u0e49\u0e15\u0e31\u0e27\u0e14\u0e33\u0e40\u0e19\u0e34\u0e19\u0e01\u0e32\u0e23\u0e2a\u0e32\u0e21\u0e32\u0e23\u0e16\u0e17\u0e33\u0e07\u0e32\u0e19\u0e41\u0e15\u0e01\u0e15\u0e48\u0e32\u0e07\u0e01\u0e31\u0e19\u0e15\u0e32\u0e21\u0e1a\u0e23\u0e34\u0e1a\u0e17\u0e02\u0e2d\u0e07\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25 \u0e08\u0e30\u0e40\u0e23\u0e35\u0e22\u0e01\u0e27\u0e48\u0e32 operator overloadding<\/p>\n<pre class=\"prettyprint lang-nix\" data-start-line=\"1\" data-visibility=\"visible\" data-highlight=\"\" data-caption=\"\">\/**\r\n * Insert your code here\r\n *\/<\/pre>\n<p><strong>\u0e1c\u0e25\u0e17\u0e35\u0e48\u0e44\u0e14\u0e49<\/strong><\/p>\n<pre class=\"prettyprint lang-plain_txt\" data-start-line=\"1\" data-visibility=\"visible\" data-highlight=\"\" data-caption=\"\">Traceback (most recent call last):\r\n...\r\nTypeError: unsupported operand type(s) for +: 'Point' and 'Point'\r\n<\/pre>\n<p>\u0e08\u0e32\u0e01\u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07 \u0e2b\u0e32\u0e01\u0e40\u0e23\u0e32\u0e43\u0e0a\u0e49 operator overloadding \u0e01\u0e31\u0e1a\u0e04\u0e25\u0e32\u0e2a\u0e17\u0e35\u0e48\u0e40\u0e23\u0e32\u0e17\u0e33\u0e01\u0e32\u0e23\u0e2a\u0e23\u0e49\u0e32\u0e07\u0e02\u0e36\u0e49\u0e19\u0e21\u0e32\u0e40\u0e2d\u0e07 \u0e08\u0e30\u0e40\u0e01\u0e34\u0e14\u0e1b\u0e31\u0e0d\u0e2b\u0e32\u0e14\u0e31\u0e07\u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07 \u0e41\u0e15\u0e48\u0e43\u0e19\u0e44\u0e1e\u0e18\u0e2d\u0e19\u0e19\u0e31\u0e49\u0e19 \u0e40\u0e23\u0e32\u0e2a\u0e32\u0e21\u0e32\u0e23\u0e16\u0e08\u0e30\u0e01\u0e33\u0e2b\u0e19\u0e14\u0e23\u0e32\u0e22\u0e25\u0e30\u0e40\u0e2d\u0e35\u0e22\u0e14\u0e40\u0e1e\u0e37\u0e48\u0e2d\u0e43\u0e2b\u0e49\u0e44\u0e1e\u0e18\u0e2d\u0e19\u0e23\u0e39\u0e49\u0e16\u0e36\u0e07\u0e27\u0e34\u0e18\u0e35\u0e01\u0e32\u0e23\u0e08\u0e31\u0e14\u0e01\u0e32\u0e23\u0e01\u0e31\u0e1a\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e14\u0e31\u0e07\u0e01\u0e25\u0e48\u0e32\u0e27\u0e44\u0e14\u0e49<\/p>\n<p><strong>special function<\/strong><br \/>\n\u0e1f\u0e31\u0e07\u0e01\u0e4c\u0e0a\u0e31\u0e19\u0e02\u0e2d\u0e07\u0e04\u0e25\u0e32\u0e2a\u0e17\u0e35\u0e48\u0e40\u0e23\u0e34\u0e48\u0e21\u0e15\u0e49\u0e19\u0e14\u0e49\u0e27\u0e22 &#8220;__&#8221; \u0e19\u0e31\u0e49\u0e19\u0e08\u0e30\u0e16\u0e39\u0e01\u0e40\u0e23\u0e35\u0e22\u0e01\u0e27\u0e48\u0e32 special function \u0e40\u0e0a\u0e48\u0e19 \u0e1f\u0e31\u0e07\u0e01\u0e4c\u0e0a\u0e31\u0e19 __init__ \u0e0b\u0e36\u0e48\u0e07\u0e08\u0e30\u0e16\u0e39\u0e01\u0e40\u0e23\u0e35\u0e22\u0e01\u0e02\u0e36\u0e49\u0e19\u0e16\u0e39\u0e01\u0e04\u0e23\u0e31\u0e49\u0e07\u0e17\u0e35\u0e48\u0e21\u0e35\u0e01\u0e32\u0e23\u0e2a\u0e23\u0e49\u0e32\u0e07\u0e2d\u0e2d\u0e1a\u0e40\u0e08\u0e47\u0e04\u0e43\u0e2b\u0e21\u0e48\u0e08\u0e32\u0e01\u0e04\u0e25\u0e32\u0e2a\u0e19\u0e31\u0e49\u0e19\u0e46 \u0e01\u0e32\u0e23\u0e01\u0e33\u0e2b\u0e19\u0e14 special function \u0e19\u0e35\u0e49 \u0e08\u0e30\u0e17\u0e33\u0e43\u0e2b\u0e49\u0e04\u0e25\u0e32\u0e2a\u0e17\u0e35\u0e48\u0e40\u0e23\u0e32\u0e17\u0e33\u0e01\u0e32\u0e23\u0e2a\u0e23\u0e49\u0e32\u0e07\u0e02\u0e36\u0e49\u0e19\u0e21\u0e32\u0e43\u0e2b\u0e21\u0e48\u0e19\u0e31\u0e49\u0e19 compatible \u0e01\u0e31\u0e1a built-in class<br \/>\n<strong>\u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e01\u0e32\u0e23\u0e43\u0e0a\u0e49\u0e07\u0e32\u0e19<\/strong><\/p>\n<pre class=\"prettyprint lang-python\" data-start-line=\"1\" data-visibility=\"visible\" data-highlight=\"\" data-caption=\"\">p1 = Point(2, 3)\r\nprint( p1 )\r\n<\/pre>\n<p><strong>\u0e1c\u0e25\u0e17\u0e35\u0e48\u0e44\u0e14\u0e49<\/strong><\/p>\n<pre class=\"prettyprint lang-plain_txt\" data-start-line=\"1\" data-visibility=\"visible\" data-highlight=\"\" data-caption=\"\">&lt;__main__.Point object at 0x00000000031F8CC0&gt;\r\n<\/pre>\n<p>\u0e0b\u0e36\u0e49\u0e07\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e17\u0e35\u0e48\u0e1b\u0e23\u0e34\u0e19\u0e17\u0e4c\u0e2d\u0e2d\u0e01\u0e21\u0e32\u0e44\u0e14\u0e49\u0e19\u0e31\u0e49\u0e19\u0e22\u0e31\u0e07\u0e44\u0e21\u0e48\u0e04\u0e48\u0e2d\u0e22\u0e2a\u0e37\u0e48\u0e2d\u0e04\u0e27\u0e32\u0e21\u0e2b\u0e21\u0e32\u0e22\u0e21\u0e32\u0e01\u0e19\u0e31\u0e01 \u0e41\u0e15\u0e48\u0e2b\u0e32\u0e01\u0e40\u0e23\u0e32\u0e17\u0e33\u0e01\u0e32\u0e23\u0e01\u0e33\u0e2b\u0e19\u0e14\u0e23\u0e32\u0e22\u0e25\u0e30\u0e40\u0e2d\u0e35\u0e22\u0e14\u0e25\u0e07\u0e44\u0e1b\u0e43\u0e19\u0e1f\u0e31\u0e07\u0e01\u0e4c\u0e0a\u0e31\u0e19 __str__() \u0e02\u0e2d\u0e07\u0e04\u0e25\u0e32\u0e2a\u0e17\u0e35\u0e48\u0e40\u0e23\u0e32\u0e2a\u0e23\u0e49\u0e32\u0e07\u0e02\u0e36\u0e49\u0e19 \u0e40\u0e23\u0e32\u0e2a\u0e32\u0e21\u0e32\u0e23\u0e16\u0e08\u0e30\u0e1b\u0e23\u0e34\u0e19\u0e17\u0e4c\u0e04\u0e48\u0e32\u0e17\u0e35\u0e48\u0e2a\u0e37\u0e48\u0e2d\u0e04\u0e27\u0e32\u0e21\u0e2b\u0e21\u0e32\u0e22\u0e44\u0e14\u0e49\u0e21\u0e32\u0e01\u0e02\u0e36\u0e49\u0e19<br \/>\n<strong>\u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e01\u0e32\u0e23\u0e43\u0e0a\u0e49\u0e07\u0e32\u0e19<\/strong><\/p>\n<pre class=\"prettyprint lang-python\" data-start-line=\"1\" data-visibility=\"visible\" data-highlight=\"\" data-caption=\"\">class Point:\r\n     def __init__(self, x=0, y=0):\r\n          self.x = x\r\n          self.y = y\r\n\r\n     def __str__(self):\r\n          return \"({0}, {1})\".format(self.x, self.y)\r\n\r\np1 = Point(1, 5)\r\nprint( p1 )\r\n<\/pre>\n<p><strong>\u0e1c\u0e25\u0e17\u0e35\u0e48\u0e44\u0e14\u0e49<\/strong><\/p>\n<pre class=\"prettyprint lang-plain_txt\" data-start-line=\"1\" data-visibility=\"visible\" data-highlight=\"\" data-caption=\"\">(1, 5)\r\n<\/pre>\n<p>\u0e08\u0e32\u0e01\u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07 \u0e40\u0e21\u0e37\u0e48\u0e2d\u0e40\u0e23\u0e32\u0e17\u0e33\u0e01\u0e32\u0e23\u0e01\u0e33\u0e2b\u0e19\u0e14\u0e23\u0e32\u0e22\u0e25\u0e30\u0e40\u0e2d\u0e35\u0e22\u0e14\u0e43\u0e2b\u0e49\u0e01\u0e31\u0e1a\u0e1f\u0e31\u0e07\u0e01\u0e4c\u0e0a\u0e31\u0e19 __str__ \u0e41\u0e25\u0e49\u0e27\u0e40\u0e21\u0e37\u0e48\u0e2d\u0e17\u0e33\u0e01\u0e32\u0e23\u0e1e\u0e34\u0e21\u0e1e\u0e4c\u0e04\u0e48\u0e32\u0e2d\u0e2d\u0e01\u0e21\u0e32 \u0e04\u0e48\u0e32\u0e14\u0e31\u0e07\u0e01\u0e25\u0e48\u0e32\u0e27 \u0e2a\u0e37\u0e48\u0e2d\u0e04\u0e27\u0e32\u0e21\u0e2b\u0e21\u0e32\u0e22\u0e16\u0e36\u0e07\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e21\u0e32\u0e01\u0e02\u0e36\u0e49\u0e19<\/p>\n<pre class=\"prettyprint lang-python\" data-start-line=\"1\" data-visibility=\"visible\" data-highlight=\"\" data-caption=\"\">class Point:\r\n     def __init__(self, x=0, y=0):\r\n          self.x = x\r\n          self.y = y\r\n\r\n     def __str__(self):\r\n          return \"({0}, {1})\".format(self.x, self.y)\r\n\r\np1 = Point(5, -2)\r\nprint( str(p1) )\r\nprint( format(p1) )\r\n<\/pre>\n<p><strong>\u0e1c\u0e25\u0e17\u0e35\u0e48\u0e44\u0e14\u0e49<\/strong><\/p>\n<pre class=\"prettyprint lang-plain_txt\" data-start-line=\"1\" data-visibility=\"visible\" data-highlight=\"\" data-caption=\"\">(5, -2)\r\n(5, -2)\r\n<\/pre>\n<p>\u0e40\u0e21\u0e37\u0e48\u0e2d\u0e40\u0e23\u0e32\u0e43\u0e0a\u0e49\u0e04\u0e33\u0e2a\u0e31\u0e48\u0e07 str( p1 ) \u0e2b\u0e23\u0e37\u0e2d format( p1 ) \u0e44\u0e1e\u0e18\u0e2d\u0e19\u0e40\u0e2d\u0e07\u0e08\u0e30\u0e40\u0e23\u0e35\u0e22\u0e01\u0e43\u0e0a\u0e49\u0e1f\u0e31\u0e07\u0e01\u0e4c\u0e0a\u0e31\u0e19 p1.__str__() \u0e20\u0e32\u0e22\u0e43\u0e19\u0e2d\u0e31\u0e15\u0e42\u0e19\u0e21\u0e31\u0e15\u0e34<\/p>\n<p>\u0e01\u0e32\u0e23 overloading \u0e01\u0e31\u0e1a\u0e15\u0e31\u0e27\u0e14\u0e33\u0e40\u0e19\u0e34\u0e19\u0e01\u0e32\u0e23 &#8220;+&#8221;<br \/>\n\u0e2b\u0e32\u0e01\u0e15\u0e49\u0e2d\u0e07\u0e01\u0e32\u0e23\u0e08\u0e30\u0e17\u0e33\u0e01\u0e32\u0e23 overload \u0e08\u0e32\u0e01\u0e15\u0e31\u0e27\u0e14\u0e33\u0e40\u0e19\u0e34\u0e19\u0e01\u0e32\u0e23 &#8220;+&#8221; \u0e40\u0e23\u0e32\u0e15\u0e49\u0e2d\u0e07\u0e17\u0e33\u0e01\u0e32\u0e23 implement \u0e1f\u0e31\u0e07\u0e01\u0e4c\u0e0a\u0e31\u0e19 __add__() \u0e43\u0e19\u0e04\u0e25\u0e32\u0e2a\u0e17\u0e35\u0e48\u0e40\u0e23\u0e32\u0e17\u0e33\u0e01\u0e32\u0e23\u0e2a\u0e23\u0e49\u0e32\u0e07\u0e02\u0e36\u0e49\u0e19\u0e21\u0e32\u0e43\u0e2b\u0e21\u0e48 \u0e40\u0e23\u0e32\u0e2a\u0e32\u0e21\u0e32\u0e23\u0e16\u0e01\u0e33\u0e2b\u0e19\u0e14\u0e40\u0e23\u0e32\u0e25\u0e30\u0e40\u0e2d\u0e35\u0e22\u0e14\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e44\u0e23\u0e01\u0e47\u0e44\u0e14\u0e49\u0e20\u0e32\u0e22\u0e43\u0e19\u0e1f\u0e31\u0e07\u0e01\u0e4c\u0e0a\u0e31\u0e19 \u0e41\u0e15\u0e48\u0e40\u0e21\u0e37\u0e48\u0e2d\u0e15\u0e49\u0e2d\u0e07\u0e17\u0e33\u0e01\u0e32\u0e23\u0e04\u0e37\u0e19\u0e04\u0e48\u0e32\u0e2d\u0e2d\u0e01\u0e21\u0e32\u0e15\u0e49\u0e2d\u0e07\u0e04\u0e37\u0e19\u0e04\u0e48\u0e32\u0e2d\u0e2d\u0e01\u0e21\u0e32\u0e43\u0e19\u0e23\u0e39\u0e1b\u0e41\u0e1a\u0e1a\u0e02\u0e2d\u0e07\u0e2d\u0e2d\u0e1a\u0e40\u0e08\u0e47\u0e04 Point \u0e0b\u0e36\u0e48\u0e07\u0e40\u0e1b\u0e47\u0e19\u0e1c\u0e25\u0e23\u0e27\u0e21\u0e02\u0e2d\u0e07\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e17\u0e31\u0e49\u0e07\u0e2a\u0e2d\u0e07\u0e17\u0e35\u0e48\u0e2a\u0e48\u0e07\u0e40\u0e02\u0e49\u0e32\u0e44\u0e1b\u0e14\u0e33\u0e40\u0e19\u0e34\u0e19\u0e01\u0e32\u0e23<\/p>\n<pre class=\"prettyprint lang-python\" data-start-line=\"1\" data-visibility=\"visible\" data-highlight=\"\" data-caption=\"\">class Point:\r\n     def __init__(self, x=0, y=0):\r\n          self.x = x\r\n          self.y = y\r\n\r\n     def __str__(self):\r\n          return \"({0}, {1})\".format(self.x, self.y)\r\n\r\n     def __add__(self, other):\r\n          x = self.x + other.x\r\n          y = self.y + other.y\r\n          return Point(x, y)\r\n\r\npoint1 = Point(5, -2)\r\npoint2 = Point(3, 7)\r\nresult = point1 + point2\r\nprint( result )\r\n<\/pre>\n<p><strong>\u0e1c\u0e25\u0e17\u0e35\u0e48\u0e44\u0e14\u0e49<\/strong><\/p>\n<pre class=\"prettyprint lang-plain_txt\" data-start-line=\"1\" data-visibility=\"visible\" data-highlight=\"\" data-caption=\"\">(2, 5)\r\n<\/pre>\n<p>\u0e08\u0e32\u0e01\u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07 \u0e40\u0e21\u0e37\u0e48\u0e2d\u0e40\u0e23\u0e32\u0e17\u0e33\u0e01\u0e32\u0e23\u0e04\u0e33\u0e19\u0e27\u0e13\u0e1c\u0e25\u0e23\u0e27\u0e21\u0e02\u0e2d\u0e07\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25 point1+point2 \u0e44\u0e1e\u0e18\u0e2d\u0e19\u0e08\u0e30\u0e40\u0e23\u0e35\u0e22\u0e01\u0e1f\u0e31\u0e07\u0e01\u0e4c\u0e0a\u0e31\u0e19 point1.__add__(point2) \u0e0b\u0e36\u0e48\u0e07\u0e01\u0e47\u0e40\u0e17\u0e35\u0e22\u0e1a\u0e40\u0e17\u0e48\u0e32 Point.__add__(point1, point2) \u0e43\u0e19\u0e17\u0e33\u0e19\u0e2d\u0e07\u0e40\u0e14\u0e35\u0e22\u0e27\u0e01\u0e31\u0e19 \u0e40\u0e23\u0e32\u0e2a\u0e32\u0e21\u0e32\u0e23\u0e16\u0e17\u0e35\u0e48\u0e08\u0e30\u0e17\u0e33\u0e01\u0e32\u0e23 overload \u0e40\u0e04\u0e23\u0e37\u0e48\u0e2d\u0e07\u0e2b\u0e21\u0e32\u0e22\u0e14\u0e33\u0e40\u0e19\u0e34\u0e19\u0e01\u0e32\u0e23\u0e2d\u0e37\u0e48\u0e19\u0e46 \u0e44\u0e14\u0e49\u0e2d\u0e35\u0e01\u0e41\u0e25\u0e30 special function \u0e17\u0e35\u0e48\u0e40\u0e23\u0e32\u0e08\u0e33\u0e40\u0e1b\u0e47\u0e19\u0e15\u0e49\u0e2d\u0e07\u0e23\u0e30\u0e1a\u0e38\u0e23\u0e32\u0e22\u0e25\u0e30\u0e40\u0e2d\u0e35\u0e22\u0e14\u0e2a\u0e33\u0e2b\u0e23\u0e31\u0e1a\u0e15\u0e31\u0e27\u0e14\u0e33\u0e40\u0e19\u0e34\u0e19\u0e01\u0e32\u0e23\u0e19\u0e31\u0e49\u0e19\u0e46 \u0e14\u0e31\u0e07\u0e23\u0e32\u0e22\u0e25\u0e30\u0e40\u0e2d\u0e35\u0e22\u0e14\u0e43\u0e19\u0e15\u0e32\u0e23\u0e32\u0e07\u0e14\u0e49\u0e32\u0e19\u0e25\u0e48\u0e32\u0e07<\/p>\n<table>\n<thead>\n<tr>\n<th>Operator<\/th>\n<th>Expression<\/th>\n<th>Internally<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Addition<\/td>\n<td>p1 + p2<\/td>\n<td>p1.__add__(p2)<\/td>\n<\/tr>\n<tr>\n<td>Subtraction<\/td>\n<td>p1 &#8211; p2<\/td>\n<td>p1.__sub__(p2)<\/td>\n<\/tr>\n<tr>\n<td>Multiplication<\/td>\n<td>p1 * p2<\/td>\n<td>p1.__mul__(p2)<\/td>\n<\/tr>\n<tr>\n<td>Power<\/td>\n<td>p1 ** p2<\/td>\n<td>p1.__pow__(p2)<\/td>\n<\/tr>\n<tr>\n<td>Division<\/td>\n<td>p1 \/ p2<\/td>\n<td>p1.__truediv__(p2)<\/td>\n<\/tr>\n<tr>\n<td>Floor Division<\/td>\n<td>p1 \/\/ p2<\/td>\n<td>p1.__floordiv__(p2)<\/td>\n<\/tr>\n<tr>\n<td>Remainder (modulo)<\/td>\n<td>p1 % p2<\/td>\n<td>p1.__mod__(p2)<\/td>\n<\/tr>\n<tr>\n<td>Bitwise left shift<\/td>\n<td>p1 &lt;&lt; p2<\/td>\n<td>p1.__lshift__(p2)<\/td>\n<\/tr>\n<tr>\n<td>Bitwise right shift<\/td>\n<td>p1 &gt;&gt; p2<\/td>\n<td>p1.__rshift__(p2)<\/td>\n<\/tr>\n<tr>\n<td>Bitwise AND<\/td>\n<td>p1 &amp; p2<\/td>\n<td>p1.__and__(p2)<\/td>\n<\/tr>\n<tr>\n<td>Bitwise OR<\/td>\n<td>p1 | p2<\/td>\n<td>p1.__or__(p2)<\/td>\n<\/tr>\n<tr>\n<td>Bitwise XOR<\/td>\n<td>p1 ^ p2<\/td>\n<td>p1.__xor__(p2)<\/td>\n<\/tr>\n<tr>\n<td>Bitwise NOT<\/td>\n<td>~p1<\/td>\n<td>p1.__invert__()<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Overloading comparison operator<\/strong><br \/>\n\u0e44\u0e1e\u0e18\u0e2d\u0e19\u0e44\u0e21\u0e48\u0e44\u0e14\u0e49\u0e08\u0e33\u0e01\u0e31\u0e14 operator overloading \u0e40\u0e09\u0e1e\u0e32\u0e30\u0e01\u0e32\u0e23\u0e14\u0e33\u0e40\u0e19\u0e34\u0e19\u0e01\u0e32\u0e23\u0e17\u0e32\u0e07\u0e04\u0e13\u0e34\u0e15\u0e28\u0e32\u0e2a\u0e32\u0e15\u0e23\u0e4c \u0e40\u0e23\u0e32\u0e2a\u0e32\u0e21\u0e32\u0e23\u0e16\u0e08\u0e30 overload \u0e2a\u0e33\u0e2b\u0e23\u0e31\u0e1a\u0e15\u0e31\u0e27\u0e14\u0e33\u0e40\u0e19\u0e34\u0e19\u0e01\u0e32\u0e23\u0e40\u0e1b\u0e23\u0e35\u0e22\u0e1a\u0e40\u0e17\u0e35\u0e22\u0e1a\u0e44\u0e14\u0e49\u0e40\u0e0a\u0e48\u0e19\u0e01\u0e31\u0e19 \u0e42\u0e14\u0e22\u0e2b\u0e32\u0e01\u0e40\u0e23\u0e32\u0e15\u0e49\u0e2d\u0e07\u0e01\u0e32\u0e23\u0e08\u0e30\u0e17\u0e33\u0e07\u0e32\u0e19\u0e01\u0e31\u0e1a\u0e40\u0e04\u0e23\u0e37\u0e48\u0e2d\u0e07\u0e2b\u0e21\u0e32\u0e22 &lt; \u0e43\u0e19\u0e04\u0e25\u0e32\u0e2a Point \u0e42\u0e14\u0e22\u0e08\u0e30\u0e17\u0e33\u0e01\u0e32\u0e23\u0e40\u0e1b\u0e23\u0e35\u0e22\u0e1a\u0e40\u0e17\u0e35\u0e22\u0e1a magnitude \u0e02\u0e2d\u0e07 Point \u0e40\u0e2b\u0e25\u0e48\u0e32\u0e19\u0e35\u0e49\u0e01\u0e31\u0e1a\u0e08\u0e38\u0e14\u0e40\u0e23\u0e34\u0e48\u0e21\u0e15\u0e49\u0e19 \u0e41\u0e25\u0e30\u0e04\u0e37\u0e19\u0e04\u0e48\u0e32\u0e40\u0e1b\u0e47\u0e19\u0e1c\u0e25\u0e08\u0e32\u0e01\u0e04\u0e33\u0e19\u0e27\u0e13\u0e14\u0e31\u0e07\u0e01\u0e25\u0e48\u0e32\u0e27<br \/>\n<strong>\u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e01\u0e32\u0e23\u0e43\u0e0a\u0e49\u0e07\u0e32\u0e19<\/strong><\/p>\n<pre class=\"prettyprint lang-python\" data-start-line=\"1\" data-visibility=\"visible\" data-highlight=\"\" data-caption=\"\">class Point:\r\n     def __init__(self, x=0, y=0):\r\n          self.x = x\r\n          self.y = y\r\n\r\n     def __str__(self):\r\n          return \"({0}, {1})\".format(self.x, self.y)\r\n\r\n     def __lt__(self, other):\r\n          self_mag = (self.x ** 2) + (self.y ** 2)\r\n          other_mag = (other.x ** 2) + (other.y ** 2)\r\n          return self_mag &lt; other_mag\r\n\r\nprint( Point(1, 1) &lt; Point(-2, -3) )\r\n# True\r\n\r\nprint( Point(1,1) &lt; Point(0.5,-0.2) )\r\n#False\r\n\r\nprint( Point(1,1) &lt; Point(1,1) )\r\n#False\r\n<\/pre>\n<p>\u0e2a\u0e33\u0e2b\u0e23\u0e31\u0e1a special function \u0e17\u0e35\u0e48\u0e40\u0e23\u0e32\u0e15\u0e49\u0e2d\u0e07\u0e01\u0e32\u0e23 implement \u0e40\u0e1e\u0e37\u0e48\u0e2d\u0e08\u0e30 overload \u0e01\u0e32\u0e23\u0e14\u0e33\u0e40\u0e19\u0e34\u0e19\u0e01\u0e32\u0e23\u0e40\u0e1b\u0e23\u0e35\u0e22\u0e1a\u0e40\u0e17\u0e35\u0e22\u0e1a \u0e15\u0e32\u0e21\u0e23\u0e32\u0e22\u0e25\u0e30\u0e40\u0e2d\u0e35\u0e22\u0e14\u0e15\u0e32\u0e23\u0e32\u0e07\u0e14\u0e49\u0e32\u0e19\u0e25\u0e48\u0e32\u0e07<\/p>\n<table>\n<thead>\n<tr>\n<th>Operator<\/th>\n<th>Expression<\/th>\n<th>Internally<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Less than<\/td>\n<td>p1 &lt; p2<\/td>\n<td>p1.__lt__(p2)<\/td>\n<\/tr>\n<tr>\n<td>Less than or equal to<\/td>\n<td>p1 &lt;= p2<\/td>\n<td>p1.__le__(p2)<\/td>\n<\/tr>\n<tr>\n<td>Equal to<\/td>\n<td>p1 == p2<\/td>\n<td>p1.__eq__(p2)<\/td>\n<\/tr>\n<tr>\n<td>Not equal to<\/td>\n<td>p1 != p2<\/td>\n<td>p1.__ne__(p2)<\/td>\n<\/tr>\n<tr>\n<td>Greater than<\/td>\n<td>p1 &gt; p2<\/td>\n<td>p1.__gt__(p2)<\/td>\n<\/tr>\n<tr>\n<td>Greater than or equal to<\/td>\n<td>p1 &gt;= p2<\/td>\n<td>p1.__ge__(p2)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>operator overloading \u0e15\u0e31\u0e27\u0e14\u0e33\u0e40\u0e19\u0e34\u0e19\u0e01\u0e32\u0e23(operator) \u0e17\u0e33\u0e07\u0e32\u0e19\u0e01\u0e31\u0e1a built-in class \u0e41\u0e15\u0e48\u0e17\u0e33\u0e07\u0e32\u0e19\u0e41\u0e15\u0e01\u0e15\u0e48\u0e32\u0e07\u0e01\u0e31\u0e19\u0e15\u0e32\u0e21\u0e0a\u0e19\u0e34\u0e14\u0e02\u0e2d\u0e07\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25 \u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e40\u0e0a\u0e48\u0e19 \u0e15\u0e31\u0e27\u0e14\u0e33\u0e40\u0e19\u0e34\u0e19\u0e01\u0e32\u0e23 &#8220;+&#8221; \u0e08\u0e30\u0e14\u0e33\u0e40\u0e19\u0e34\u0e19\u0e01\u0e32\u0e23\u0e40\u0e1e\u0e37\u0e48\u0e2d\u0e1a\u0e27\u0e01\u0e08\u0e33\u0e19\u0e27\u0e19 2 \u0e08\u0e33\u0e19\u0e27\u0e19 \u0e2b\u0e23\u0e37\u0e2d \u0e2d\u0e32\u0e08\u0e08\u0e30\u0e43\u0e0a\u0e49\u0e40\u0e1e\u0e37\u0e48\u0e2d\u0e17\u0e33\u0e01\u0e32\u0e23\u0e40\u0e0a\u0e37\u0e48\u0e2d\u0e21\u0e02\u0e49\u0e2d\u0e04\u0e27\u0e32\u0e21 2 \u0e02\u0e49\u0e2d\u0e04\u0e27\u0e32\u0e21\u0e01\u0e47\u0e44\u0e14\u0e49 \u0e04\u0e38\u0e13\u0e25\u0e31\u0e01\u0e29\u0e13\u0e30\u0e40\u0e0a\u0e48\u0e19\u0e19\u0e35\u0e49 \u0e0b\u0e36\u0e48\u0e07\u0e2d\u0e19\u0e38\u0e0d\u0e32\u0e15\u0e34\u0e43\u0e2b\u0e49\u0e15\u0e31\u0e27\u0e14\u0e33\u0e40\u0e19\u0e34\u0e19\u0e01\u0e32\u0e23\u0e2a\u0e32\u0e21\u0e32\u0e23\u0e16\u0e17\u0e33\u0e07\u0e32\u0e19\u0e41\u0e15\u0e01\u0e15\u0e48\u0e32\u0e07\u0e01\u0e31\u0e19\u0e15\u0e32\u0e21\u0e1a\u0e23\u0e34\u0e1a\u0e17\u0e02\u0e2d\u0e07\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25 \u0e08\u0e30\u0e40\u0e23\u0e35\u0e22\u0e01\u0e27\u0e48\u0e32 operator overloadding \/** * Insert your code here *\/ \u0e1c\u0e25\u0e17\u0e35\u0e48\u0e44\u0e14\u0e49 Traceback (most recent call last): &#8230; TypeError: unsupported operand type(s) for +: &#8216;Point&#8217; and &#8216;Point&#8217; \u0e08\u0e32\u0e01\u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07 \u0e2b\u0e32\u0e01\u0e40\u0e23\u0e32\u0e43\u0e0a\u0e49 operator overloadding \u0e01\u0e31\u0e1a\u0e04\u0e25\u0e32\u0e2a\u0e17\u0e35\u0e48\u0e40\u0e23\u0e32\u0e17\u0e33\u0e01\u0e32\u0e23\u0e2a\u0e23\u0e49\u0e32\u0e07\u0e02\u0e36\u0e49\u0e19\u0e21\u0e32\u0e40\u0e2d\u0e07 \u0e08\u0e30\u0e40\u0e01\u0e34\u0e14\u0e1b\u0e31\u0e0d\u0e2b\u0e32\u0e14\u0e31\u0e07\u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07 \u0e41\u0e15\u0e48\u0e43\u0e19\u0e44\u0e1e\u0e18\u0e2d\u0e19\u0e19\u0e31\u0e49\u0e19 \u0e40\u0e23\u0e32\u0e2a\u0e32\u0e21\u0e32\u0e23\u0e16\u0e08\u0e30\u0e01\u0e33\u0e2b\u0e19\u0e14\u0e23\u0e32\u0e22\u0e25\u0e30\u0e40\u0e2d\u0e35\u0e22\u0e14\u0e40\u0e1e\u0e37\u0e48\u0e2d\u0e43\u0e2b\u0e49\u0e44\u0e1e\u0e18\u0e2d\u0e19\u0e23\u0e39\u0e49\u0e16\u0e36\u0e07\u0e27\u0e34\u0e18\u0e35\u0e01\u0e32\u0e23\u0e08\u0e31\u0e14\u0e01\u0e32\u0e23\u0e01\u0e31\u0e1a\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e14\u0e31\u0e07\u0e01\u0e25\u0e48\u0e32\u0e27\u0e44\u0e14\u0e49 special function <a href=\"https:\/\/www.booboohome.com\/blogs\/2018\/09\/python-operator-overloading\/\" rel=\"nofollow\"><span class=\"sr-only\">Read more about Python &#8211; Operator Overloading<\/span>[&hellip;]<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[91,95],"tags":[180,92,113,115,94,181,114],"class_list":["post-1722","post","type-post","status-publish","format-standard","hentry","category-python","category-python-tutorial","tag-operator-overloading","tag-python","tag-python-tutorial","tag-115","tag-94","tag--overloading","tag-114"],"_links":{"self":[{"href":"https:\/\/www.booboohome.com\/blogs\/wp-json\/wp\/v2\/posts\/1722","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.booboohome.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.booboohome.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.booboohome.com\/blogs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.booboohome.com\/blogs\/wp-json\/wp\/v2\/comments?post=1722"}],"version-history":[{"count":8,"href":"https:\/\/www.booboohome.com\/blogs\/wp-json\/wp\/v2\/posts\/1722\/revisions"}],"predecessor-version":[{"id":3564,"href":"https:\/\/www.booboohome.com\/blogs\/wp-json\/wp\/v2\/posts\/1722\/revisions\/3564"}],"wp:attachment":[{"href":"https:\/\/www.booboohome.com\/blogs\/wp-json\/wp\/v2\/media?parent=1722"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.booboohome.com\/blogs\/wp-json\/wp\/v2\/categories?post=1722"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.booboohome.com\/blogs\/wp-json\/wp\/v2\/tags?post=1722"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}