首页 > 编程语言 > 详细

python 小练习2

时间:2018-04-04 17:13:36      阅读:183      评论:0      收藏:0      [点我收藏+]

1、过滤问题

找出以ip开头的字符串
_input = [ip_10.2.223.5, ip_10.2.220.3, port_22, port_8001, port_80, ip_172.16.8.35]

for item in _input:
    if item.startswith(ip):
        print(item)

技术分享图片

 

内建函数filter(fucn,seq)

python2:中,返回结果是一个列表
python3中:返回filter对象

 

def get_int(n):
    if isinstance(n,int):
        return True
    else:
        return False
    
_input = [1, 2, 3, "ss", "test", [1, 2]]
    
ret = []

for item in filter(get_int,_input):
    ret.append(item)
    
print(ret)

 

技术分享图片

 

python 小练习2

原文:https://www.cnblogs.com/hellojackyleon/p/8718215.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!