# -*- coding: utf-8 -*- #使用内建的isinstance函数可以判断一个变量是不是字符串: x = 123 y = 'abc' print(isinstance(x,str))#false print(isinstance(y,str))#true #列表生成式 L1 = ['Hello', 'World', 18, 'Apple', None] L2 = [a.lower() for a in L1 if isinstance(a,str)] print L2
列表生成式
原创
©著作权归作者所有:来自51CTO博客作者sukijia的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:python的简单迭代
下一篇:类与对象简易例子
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Python之列表生成式、生成器
列表生成式 ——可以快速生成list,可以通过一个list推导出另一个list,而代码却十分简洁: >>> [x * x for x in range(1, 1
python之列表生成式 python之生成器 生成器 迭代 python