-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperatorOverloading.py
More file actions
executable file
·52 lines (36 loc) · 1.12 KB
/
operatorOverloading.py
File metadata and controls
executable file
·52 lines (36 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Andre Augusto Giannotti Scota (https://sites.google.com/view/a2gs/)
import sys, os
# https://docs.python.org/3/reference/datamodel.html#special-method-names
# All class inherited from 'Object' class
class objTest:
n = int()
s = str()
def __init__(self, nnn, sss):
self.n = nnn
self.s = sss
def __str__(self):
return(f"My content are: {self.n} and {self.s}")
def __eq__(self, other):
print(f'{self.n} == {other.n} and {self.s} == {other.s}')
return(self.n == other.n and self.s == other.s)
def __lt__(self, other):
print(f'{self.n} < {other.n}')
return(self.n < other.n)
def __add__(self, other):
print(f'{self.n} + {other.n}')
return(self.n + other.n)
sample1 = objTest(10, "abc")
sample2 = objTest(20, "xyz")
print(sample1)
print(sample2)
print("=== 1 ==================================")
print("sample1 + sample2: ")
print(sample1 + sample2)
print("=== 2 ==================================")
print("sample1 == sample2?")
print(sample1 == sample2)
print("=== 3 ==================================")
print("sample1 < sample2?")
print(sample1 < sample2)