在python中將函數封裝成類的方法
1.封裝一個階乘類
class JieChengCount(object):
def __init__(self,n):
self.n = n
# 階乘求積
def jc(self,n):
result = 1
if n == 0:
return result
else:
for i in range(1, n + 1): # 1到n的積
result *= i
return result
2.封裝一個求和類
def count:
count = 0
for i in range(0, int(n)): # 0到num的和
print(count)