Discuss / Python / 交作业

交作业

Topic source

聽Amy

#1 Created at ... [Delete] [Delete and Lock User]

L1 = ['Hello', 'World', 18, 'Apple', None] L2 = [x.lower() for x in L1 if isinstance(x,str)]

Curious梁焰

#2 Created at ... [Delete] [Delete and Lock User]

请问为什么可以直接在遍历L1后面直接加判断,这是什么语法?

L1 = ['Hello', 'World', 18, 'Apple', None] s=[L2.lower() for L2 in L1 if isinstance(L2,str)==1] print(s)


  • 1

Reply