python-基础案例7

1、写函数,接收n个数字,求这些参数数字的和。

def sum_func(*args):
	total = 0
	for i in args:
		total += i
	return total
print(sum_func(1,2,3,8,23,6))
2、读代码,回答:代码中,打印出来的值a,b,c分别是什么?为什么?
a=10
b=20
def test5(a,b):
    print(a,b)  #a应该等于20,b等于10,c = test5(b,a)传的值为test5(20,10)
c = test5(b,a) 
print(c)
3、读代码,回答:代码中,打印出来的值a,b,c分别是什么?为什么?
a=10
b=20
def test5(a,b):
	a=3
	b=5
    print(a,b) #因为局部有自己有a,b的值,就不需要在用外面的值,所打印出来a=3,b=5
c = test5(b,a)
print(c)    #c的值为空,因为函数返回值为空。

猜你喜欢

转载自blog.csdn.net/weixin_41092687/article/details/86532742