86、下面的函数,哪些会输出1,2,3三个数字
def func1():
for i in range(3):
print(i)
a_list = [0, 1, 2]
for i in a_list:
print(i + 1)
def func2():
i = 1
while i < 3:
print(i)
i += 1
def func3():
for i in range(3):
print(i + 1)
# 答案
func3()
87、以下函数需要在其中引用一个全局变量k,请填写语句
def fun():
________
k=k+1
# 答案:
global k
88、请把以下函数转化为python lambda匿名函数
def add(x,y):
return x+y
# 答案
print(lambda x, y: x + y)
89、阅读以下代码,并写出程序的输出结果
my_dict = {"a":0,"b":1} 2.
def func(d):
d["a"]=1
return d
func(my_dict)
my_dict["c"]=2
print(my_dict)
# 答案
{'a': 1, 'b': 1, 'c': 2}
90、填空题
# 有函数定义如下
def calc(a,b,c,d=1,e=2):
return (a+b)*(c-d)+e
# 请分别写出以下标号代码的输出结果, 如果出错请写出 Error
print(calc(1,2,3,4,5)) # ____2
print(calc(1,2,3)) # ____8
print(calc(1,2)) # ____报错 missing 1 required positional argument: 'c'
print(calc(1,2,3,e=4)) # ____10
print(calc(e=4, c=5, a=2,b=3)) # ____24
print(calc(1,2,3, d=5, 4)) # ____SyntaxError