第一题,要求将输入参数的元素个数显示出来,那就是要用到*argv关键字参数了
自己的答案
class C:
def __init__(self,*argv):
if not argv:
print ('no input')
else:
print ('There are %d parameters,and they are '%len(argv),end='')
for i in argv:
print (i,end=' ')
c=C(1,2,3,4,5)
第二题是对重写比较操作符的魔法方法,要求比较的标准是单词长度
class Word(str):
def __lt__(self,other):
return len(self)<len(other)