# _*_ coding:utf-8 _*_
L1 = ['Hello', 'World', 18, 'Apple', None]
L2 = [x.lower() for x in L1 if isinstance(x, str)]
# 测试:
print(L2)
if L2 == ['hello', 'world', 'apple']:
print('测试通过!')
else:
print('测试失败!')
['hello', 'world', 'apple']
测试通过!
# 自然数发生器
def f():
n = 0
while True:
yield n
n = n + 1
x=f()
print(next(x))
print(next(x))
print(next(x))
print(next(x))
print(next(x))
0
1
2
3
4
def add(x, y, f):
return f(x) + f(y)
# 高阶函数,函数名作为参数
print(add(-5, 6, abs))
11