182247236
V2EX  ›  问与答

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

  •  
  •   182247236 · Oct 21, 2016 · 2440 views
    This topic created in 3494 days ago, the information mentioned may be changed or developed.
    谢了一段循环简单的语句
    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 replies    2016-10-21 17:39:57 +08:00
    182247236
        1
    182247236  
    OP
       Oct 21, 2016
    占个坑=_=
    jackyspy
        2
    jackyspy  
       Oct 21, 2016
    建议到 stackoverflow 提问
    182247236
        3
    182247236  
    OP
       Oct 21, 2016
    @jackyspy 好的好的
    waytoexplorer
        4
    waytoexplorer  
       Oct 21, 2016 via iPhone
    为什么不用 for 循环
    182247236
        5
    182247236  
    OP
       Oct 21, 2016
    @waytoexplorer 还没学到....
    rudy1224
        6
    rudy1224  
       Oct 21, 2016   ❤️ 1
    PID = ['asda','qewqw','gfdg']
    a = ["http://www.pid={}".format(pid) for pid in PID]

    over
    182247236
        7
    182247236  
    OP
       Oct 21, 2016
    @rudy1224 待会试一下
    stamaimer
        8
    stamaimer  
       Oct 21, 2016 via iPhone
    这跟 python 有啥关系?
    Sylv
        9
    Sylv  
       Oct 21, 2016 via iPhone
    建议还是静下心来找本 Python 入门书从头到尾学一遍,这些基础问题还伸手真的很没意义,还没学会走就别想能跑好。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2881 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 10:19 · PVG 18:19 · LAX 03:19 · JFK 06:19
    ♥ Do have faith in what you're doing.