Discuss / Python / 作业

作业

Topic source

L2=[x.lower() for x in L1 if not isinstance(x,str) == 0]
好不容易成功一次但是为什么跟大家的都不一样啊

阿财

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

你写的好绕,我是这么理解的(不知道对不对),not isinstance(x,str)表示x不是str类型,0就是false,也就是说 not isinstance(x,str) == 0 要两边都为false才能表达为x.lower(),而当x为str类型时刚好满足not isinstance(x,str)要为false的条件,正好可以进入到下x.lower的表达式,感觉你可以从新想想逻辑,再写一次。


  • 1

Reply