Discuss / Python / 交作业--列表生成式 外加一点点问题

交作业--列表生成式 外加一点点问题

L = ['Hello', 'World', 18, 'Apple', None]
x = [R.lower() for R in L if isinstance(R,str) is True ]
print(x)

输出的结果是['hello', 'world', 'apple'],虽然不会报错了,那怎么还能把18和None,保留呢?

我想要输出的结果是['hello', 'world', 18, 'apple', None]


  • 1

Reply