V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
182247236
V2EX  ›  问与答

刚接触 python,想解决个问题 3

  •  
  •   182247236 · 2016-10-21 15:32:30 +08:00 · 1634 次点击
    这是一个创建于 2748 天前的主题,其中的信息可能已经有所发展或是发生改变。
    谢了一段循环简单的语句
    PID = ['asda','qewqw','gfdg']
    count = len(PID) - 1
    while (count >= 0):
    a.append("http://www.pid={pid}" .format(pid=PID[count]))
    count -= 1
    count 的初始值是 2 当这段执行完了后 count 的值应该为-1 ,我需要它回归 2 这个值,因为下面还有一段 while 语句需要用到这个 count,当然我也可以添加一个 counts = len ( PID )-1 给下面那段 while 语句用,可是希望能简单点就简单点写。有没有什么方法可以实现?
    9 条回复    2016-10-21 17:39:57 +08:00
    182247236
        1
    182247236  
    OP
       2016-10-21 15:37:33 +08:00
    占个坑=_=
    jackyspy
        2
    jackyspy  
       2016-10-21 15:48:46 +08:00
    建议到 stackoverflow 提问
    182247236
        3
    182247236  
    OP
       2016-10-21 15:51:53 +08:00
    @jackyspy 好的好的
    waytoexplorer
        4
    waytoexplorer  
       2016-10-21 15:54:56 +08:00 via iPhone
    为什么不用 for 循环
    182247236
        5
    182247236  
    OP
       2016-10-21 15:56:29 +08:00
    @waytoexplorer 还没学到....
    rudy1224
        6
    rudy1224  
       2016-10-21 16:03:44 +08:00   ❤️ 1
    PID = ['asda','qewqw','gfdg']
    a = ["http://www.pid={}".format(pid) for pid in PID]

    over
    182247236
        7
    182247236  
    OP
       2016-10-21 16:17:08 +08:00
    @rudy1224 待会试一下
    stamaimer
        8
    stamaimer  
       2016-10-21 17:24:28 +08:00 via iPhone
    这跟 python 有啥关系?
    Sylv
        9
    Sylv  
       2016-10-21 17:39:57 +08:00 via iPhone
    建议还是静下心来找本 Python 入门书从头到尾学一遍,这些基础问题还伸手真的很没意义,还没学会走就别想能跑好。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1022 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 18:25 · PVG 02:25 · LAX 11:25 · JFK 14:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.