由一个例题所引发的思考
问题:
一开始,我因为考python的不定长参数然后我就简单的写了一下
def sum(*numbers):
b=0
for number in numbers:
b+=sum()
print(b)
但是少了输入问题,于是我又重新写了一下:
def sum():
# 因为要int类型,且要多个输入
a = map(int, input().split(' '))
b = 0
for c in a:
b += c
print(b)
然后,我在想能不能用类来实现:
class nember(object):
def __init__(self,a=[]):
b=0
for c in a:
b+=c
print(b)
a=list(map(int, input().split(' ')))
b=nember(a)