|
1 | 1 | __author__ = "Jerry"
|
2 |
| -__version__ = "1.2.1" |
| 2 | +__version__ = "1.2.2" |
3 | 3 |
|
4 | 4 | class NotComposedOfNumbersError(Exception):
|
5 | 5 | "不是由数字组成的字符串使用String对象的toInt()函数或toInteger()函数时抛出"
|
@@ -34,6 +34,48 @@ def __sub__(self, other):
|
34 | 34 | else:
|
35 | 35 | return String(self.__str - other)
|
36 | 36 |
|
| 37 | + def __eq__(self, other) -> bool: |
| 38 | + "等于判断" |
| 39 | + if type(other) is String: |
| 40 | + return self.__str == other.__str |
| 41 | + else: |
| 42 | + return self.__str == other |
| 43 | + |
| 44 | + def __ne__(self, other) -> bool: |
| 45 | + "不等于判断" |
| 46 | + if type(other) is String: |
| 47 | + return self.__str != other.__str |
| 48 | + else: |
| 49 | + return self.__str != other |
| 50 | + |
| 51 | + def __lt__(self, other) -> bool: |
| 52 | + "小于判断" |
| 53 | + if type(other) is String: |
| 54 | + return self.__str < other.__str |
| 55 | + else: |
| 56 | + return self.__str < other |
| 57 | + |
| 58 | + def __gt__(self, other) -> bool: |
| 59 | + "大于判断" |
| 60 | + if type(other) is String: |
| 61 | + return self.__str > other.__str |
| 62 | + else: |
| 63 | + return self.__str > other |
| 64 | + |
| 65 | + def __le__(self, other) -> bool: |
| 66 | + "小于等于判断" |
| 67 | + if type(other) is String: |
| 68 | + return self.__str <= other.__str |
| 69 | + else: |
| 70 | + return self.__str <= other |
| 71 | + |
| 72 | + def __ge__(self, other) -> bool: |
| 73 | + "大于等于判断" |
| 74 | + if type(other) is String: |
| 75 | + return self.__str >= other.__str |
| 76 | + else: |
| 77 | + return self.__str >= other |
| 78 | + |
37 | 79 | def isNumber(self):
|
38 | 80 | "判断字符串是否由数字组成,返回布尔值"
|
39 | 81 | try:
|
@@ -89,6 +131,48 @@ def __sub__(self, other):
|
89 | 131 | else:
|
90 | 132 | return Integer(self.__int - other)
|
91 | 133 |
|
| 134 | + def __eq__(self, other) -> bool: |
| 135 | + "等于判断" |
| 136 | + if type(other) is Integer: |
| 137 | + return self.__int == other.__int |
| 138 | + else: |
| 139 | + return self.__int == other |
| 140 | + |
| 141 | + def __ne__(self, other) -> bool: |
| 142 | + "不等于判断" |
| 143 | + if type(other) is Integer: |
| 144 | + return self.__int != other.__int |
| 145 | + else: |
| 146 | + return self.__int != other |
| 147 | + |
| 148 | + def __lt__(self, other) -> bool: |
| 149 | + "小于判断" |
| 150 | + if type(other) is Integer: |
| 151 | + return self.__int < other.__int |
| 152 | + else: |
| 153 | + return self.__int < other |
| 154 | + |
| 155 | + def __gt__(self, other) -> bool: |
| 156 | + "大于判断" |
| 157 | + if type(other) is Integer: |
| 158 | + return self.__int > other.__int |
| 159 | + else: |
| 160 | + return self.__int > other |
| 161 | + |
| 162 | + def __le__(self, other) -> bool: |
| 163 | + "小于等于判断" |
| 164 | + if type(other) is Integer: |
| 165 | + return self.__int <= other.__int |
| 166 | + else: |
| 167 | + return self.__int <= other |
| 168 | + |
| 169 | + def __ge__(self, other) -> bool: |
| 170 | + "大于等于判断" |
| 171 | + if type(other) is Integer: |
| 172 | + return self.__int >= other.__int |
| 173 | + else: |
| 174 | + return self.__int >= other |
| 175 | + |
92 | 176 | def toStr(self):
|
93 | 177 | "将整数转成字符串"
|
94 | 178 | return str(self.__int)
|
|
0 commit comments