如果list中既包含字符串,又包含整数,由于非字符串类型没有lower()方法,所以列表生成式会报错:
摘要:
使用内建的isinstance函数可以判断一个变量是不是字符串: L2 的分解: [s.lower() for s in L1 if isinstance(s,str) ], 便于理解用 阅读全文
posted @ 2017-11-22 18:07 cccmon 阅读(639) 评论(0) 推荐(0) 编辑
posted @ 2017-11-22 18:07 cccmon 阅读(639) 评论(0) 推荐(0) 编辑
posted @ 2017-11-22 17:12 cccmon 阅读(1862) 评论(0) 推荐(0) 编辑
posted @ 2017-11-22 12:22 cccmon 阅读(3107) 评论(0) 推荐(0) 编辑