比较python中的列表值时出现问题

use*_*758 0 python python-2.7

我有一个程序在运行时解析输出,比较从给定值的时间和打印差异,但它不按我的方式工作:

a = 'Time Taken for Response: 31 msec'

time_out = 75

if a.split()[4] > time_out:

    print "time taken is more than given conditions"

    print a.split()[4] 
Run Code Online (Sandbox Code Playgroud)

输出如下:

time taken is more than given conditions

31
Run Code Online (Sandbox Code Playgroud)

我不明白为什么程序进入循环本身时 31 < 75

任何线索或指导???

sbe*_*rry 6

您正在比较"31"和75.请尝试int(a.split()[4]) > time_out:改为.