# 函数 不确定的参数情况下 输出 n*n的和 def calc(numbers): total=0 for n in numbers: print(f'n:{n}') total=total+n*n print(f'total:{total}') return total #调用函数 result=calc((1,2)) print(f'result:{result}') ''' this x is in the funcx:--> 9 -------------- this x is in the funcx:--> 9 '''
# 函数 不确定的参数情况下 输出 n*n的和 def calc(*numbers): total=0 for n in numbers: print(f'n:{n}') total=total+n*n print(f'total:{total}') return total #调用函数 result=calc(1,2,3)# 不需要强调以元祖形式传入参数 print(f'result:{result}')