Python列表生成式练习

1 '''
2 如果list中既包含字符串,又包含整数,由于非字符串类型没有lower()方法,所以列表生成式会报错
3 使用内建的isinstance函数可以判断一个变量是不是字符串:
4 返回True 或 False
5 '''
6 L1 = ['Hello', 'World', 18, 'Apple', None]
7 print([L2.lower() for L2 in L1 if isinstance(L2, str) == True])

 

posted @ 2017-11-10 22:11  Axs  阅读(717)  评论(0编辑  收藏  举报