From 264d33a7be83fbc03c870f5d38d9cd4d16613bb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mert=20G=C3=B6r?= Date: Sun, 30 Jul 2023 17:42:19 +0300 Subject: [PATCH] radd --- python-temel/radd.py | 24 ++++++++++++++++++++++++ python-temel/radd.py~ | 23 +++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 python-temel/radd.py create mode 100644 python-temel/radd.py~ diff --git a/python-temel/radd.py b/python-temel/radd.py new file mode 100644 index 0000000..410958b --- /dev/null +++ b/python-temel/radd.py @@ -0,0 +1,24 @@ +class Sample: + def __init__(self, a): + self.a = a + + def __add__(self, s): + if isinstance(s, Sample): + return Sample(self.a + s.s) + if isinstance(s, int): + return Sample(self.a + s) + + def __radd__(self, a): + return self.a + a + + def __str__(self): + return str(self.a) + +a = 10 +s = Sample(10) + +result = s + a # s.__add__(a) +print(result) + +result = a + s # s.__radd__(a) +print(result) diff --git a/python-temel/radd.py~ b/python-temel/radd.py~ new file mode 100644 index 0000000..844236e --- /dev/null +++ b/python-temel/radd.py~ @@ -0,0 +1,23 @@ +class Sample: + def __init__(self, a): + self.a = a + + def __add__(self, s): + if isinstance(s, Sample): + return Sample(self.a + s.s) + if isinstance(s, int): + return Sample(self.a + s) + + def __radd__(self, a): + return self.a + a + + def __str__(self): + return str(self.a) + +a = 10 +s = Sample(10) + +result = s + a # s.__add__(a) +print(result) + +result = a + s # s.__radd__(a)