python--return小练习

#返回单个值,return a:
#一个return后的语句不再执行,
def calc_sum(*args):
ax = 0
for n in args:
ax = ax + n
print(ax);
return ax;

#下面这个return不再执行
print(ax);

#调用返回值,根据返回值进行操作或判断

if(calc_sum(1,2,3)>5):
print('结果大于5');
else:
print('失败');

#返回多个值,return a,b,c

#相当于返回一个touple,对其中某个元素操作要使用index索引touple[0]、 touple[1]

def is_repect_all(L):
repeatList = [];
setList = set(L);
flag=True;
if len(L) != len(setList):
flag=False;
print('存在重复,其中重复项及重复次数如下:');
for each_item in setList:
re_count = 0;
for each_item_L in L:
if each_item == each_item_L:
re_count += 1;
if (re_count >= 2):
print(each_item, L.index(each_item), ": ", re_count);

# print(all_gameid_List[L.index(each_item)]);
return flag,re_count;

else:
return flag;

#调用
#此处调用touple的第二个元素
#重复数是否超过10,如果超过,则断言失败,如果没有超过10,则断言成功

assert is_repect_all(all_userid_List)[1]<=10;
原文地址:https://www.cnblogs.com/shenyexiaoqingxin/p/10370098.html