python 基础 列表 小例子

  • 存主机ip到列表

  • host_list=[]
    netip='192.168.1'
    for hostip in range(1,254):
        ip = netip +str(hostip)
        host_list.append(ip)
    hostlist

     

  • 列表遍历

  • shoplist = [apple,mango]
    for index,value in enumerate(shoplist):
        print index,value
    
    结果 0  apple
            1 mango

     

posted @ 2017-10-26 22:05  一只宅男的自我修养  阅读(320)  评论(0)    收藏  举报