0

我有以下代码,其中只有在满足第一个条件后才应执行第二个 if 循环,有没有办法将这些组合到 if 循环?

    if Pline=mPL:
    if bestTime == None or bestTime < lastTime:
        bestTime = lastTime
        Time=(bestTime.strftime('%m-%d-%Y'))
        bestLocation = lastLocation
4

1 回答 1

3

你需要and条件:

if (Pline=mPL) and ((bestTime == None) or (bestTime < lastTime)):
        bestTime = lastTime
        Time=(bestTime.strftime('%m-%d-%Y'))
        bestLocation = lastLocation
于 2012-12-24T08:07:20.657 回答