# -*- coding: utf-8 -*-
L1 = ['Hello', 'World', 18, 'Apple', None]
L2 =[x for x in L1 if isinstance(x, str) == True]
L2 = [s.lower() for s in L2]
请修改列表生成式,通过添加if语句保证列表生成式能正确地执行:
最新推荐文章于 2024-09-15 22:31:42 发布
# -*- coding: utf-8 -*-
L1 = ['Hello', 'World', 18, 'Apple', None]
L2 =[x for x in L1 if isinstance(x, str) == True]
L2 = [s.lower() for s in L2]