Discuss / Python / python列表生成式的简介体现

python列表生成式的简介体现

Topic source

第一版 《《《《《《《《《《《《《《《《《《《《《
L1 = ['Hello', 'World', 18, 'Apple', None] L2=[] for s in L1[0:5]:

if isinstance(s,str)==True:
    L2.append(s)
else:
    pass

print([s.lower() for s in L2])

》》》》》》》》》》》》》》》》》》》》》》》》 第二版 利用python的高级函数,切片,列表生成式''' L1 = ['Hello', 'World', 18, 'Apple', None] print([s.lower() for s in L1 if isinstance(s,str)])


  • 1

Reply