摘要:
1. 写函数,计算传入数字参数的和。 def calc(x,y): res = x+y return res a = calc(10,5) print(a) 2. 写函数,检查获取传入列表或元组对象的所有奇数位索引对应的元素,并将其作为新列表返回给调用者。 a = [1,2,3,4,5,6,7,8] 阅读全文
摘要:
def g_test(): while True: n = yield # 收到的值 给n print("receive from outside:",n) g = g_test() g.__next__() # 调用生成器, 同时会发送None 到 yield for i in range(10): g.send(i) # 调用生成器, 同时发送i def consumer(name): pri 阅读全文
摘要:
abs # 求绝对值 all #Return True if bool(x) is True for all values x in the iterable.If the iterable is empty, return True. >>> a = [1,2,3] >>> all(a)True> 阅读全文