请修改列表生成式,通过添加if语句保证列表生成式能正确地执行:
L1 = ['Hello', 'World', 18, 'Apple', None] L2 = [s.lower() for s in L1 if isinstance(s,str)] L2 = [s.lower() for s in L2] print(L2)
Sign in to make a reply
我很有素质
请修改列表生成式,通过添加if语句保证列表生成式能正确地执行:
L1 = ['Hello', 'World', 18, 'Apple', None] L2 = [s.lower() for s in L1 if isinstance(s,str)] L2 = [s.lower() for s in L2] print(L2)