Skip to content

Commit 4426f63

Browse files
committed
为扩展类型Integer添加了isDivisible()方法
1 parent 26580e8 commit 4426f63

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

type.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
对Python原版类型的扩展
33
"""
44
__author__ = "Jerry"
5-
__version__ = "1.2.5"
5+
__version__ = "1.2.6"
66

77
class NotComposedOfNumbersError(Exception):
88
"不是由数字组成的字符串使用String对象的toInt()函数或toInteger()函数时抛出"
@@ -229,6 +229,13 @@ def isOdd(self):
229229
else:
230230
return True
231231

232+
def isDivisible(self, number):
233+
"判断数字是否能被某个数整除,返回布尔值"
234+
if type(number) is Integer:
235+
return self.__int % number.__int == 0
236+
else:
237+
return self.__int % number == 0
238+
232239
def replace(self, /, past, now):
233240
"在前一个括号内填写字符串内要匹配的元素,后一个括号内填入要被替换成的元素,这样所有匹配的元素都会被替换为要被替换成的元素,最后返回Integer对象"
234241
return Integer(int(self.toStr().replace(past, now)))

0 commit comments

Comments
 (0)