很多人的L2输出没有数字
Topic source说来惭愧,几分钟后才看明白逻辑,用下面的式子得到验证:
L2 = [s if not isinstance(s,str) else s.lower() for s in L1]
逻辑:
1. 首先for遍历L1中所有项
2. 然后if判断是否是str,是则转换,不是则直接打印。
- 1
说来惭愧,几分钟后才看明白逻辑,用下面的式子得到验证:
L2 = [s if not isinstance(s,str) else s.lower() for s in L1]
逻辑:
1. 首先for遍历L1中所有项
2. 然后if判断是否是str,是则转换,不是则直接打印。
小丑先生不爱笑
我看很多人的L2输出没有数字,我想应该是这样的
-- coding: utf-8 --
L1 = ['Hello', 'World', 18, 'Apple', None] L2=[s.lower() if isinstance(s,str) else s for s in L1] print(L2)