Discuss / Python / 交作业

交作业

Topic source

L1 = ['Hello','World',18,'Apple',None] L2 = [s.lower() for s in L1 if isinstance(s,str) == True] L3 = [i for i in L1 if isinstance(i,int) == True] L4 = [n for n in L1 if isinstance(n,list) == True] print(L2) print(L3) print(L4)

输出: ['hello', 'world', 'apple'] [18] []

鲱鱼菌

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

大神真厉害

可以删去==true吧。isinstance()返回值就是boolean吧。


  • 1

Reply