182247236
V2EX  ›  问与答

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

  •  
  •   182247236 · Oct 21, 2016 · 2828 views
    This topic created in 3682 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
    182247236
    OP
    Oct 21, 2016
    1
    占个坑=_=
    jackyspy
    jackyspy
    Oct 21, 2016
    2
    建议到 stackoverflow 提问
    182247236
    182247236
    OP
    Oct 21, 2016
    3
    @jackyspy 好的好的
    waytoexplorer
    waytoexplorer
    Oct 21, 2016 via iPhone
    4
    为什么不用 for 循环
    182247236
    182247236
    OP
    Oct 21, 2016
    5
    @waytoexplorer 还没学到....
    rudy1224
    rudy1224
    Oct 21, 2016❤️1
    6
    PID = ['asda','qewqw','gfdg']
    a = ["http://www.pid={}".format(pid) for pid in PID]

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