在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)