如何结合两个if?

时间:2012-12-24 07:52:01

标签: python python-2.7

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

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

1 个答案:

答案 0 :(得分:3)

您需要and条件:

if (Pline=mPL) and ((bestTime == None) or (bestTime < lastTime)):
        bestTime = lastTime
        Time=(bestTime.strftime('%m-%d-%Y'))
        bestLocation = lastLocation
相关问题