列表生成式

来源:互联网 发布:lol徐老师的淘宝店网址 编辑:程序博客网 时间:2024/06/14 23:31
print([x*x for x in range(1,11) if x%2==0])  #if表示判断条件L=['Hello','World','IBM','Apple']  #将字符串全部转换为小写print([s.lower() for s in L])print([x+y for x in 'ABC' for y in 'XYZ'])  #双层循环L=['Hello','World','IBM',18,'Apple',None]print([s.lower() for s in L if isinstance(s,str)])   #只将是str的元素转换为小写

这里写图片描述

原创粉丝点击