我正在使用 Python,版本 2.7.2。
我的任务是检查列表中的最后三个元素是否为整数?例如:
mylist = [String, Large_string_containing_integers_inside_it, 80, 40, 50]
对于上面的列表,我想检查最后三个元素是否为整数。我怎样才能做到这一点?
这是我正在测试的代码:
#!/usr/bin/python
line = ['MKS_TEST', 'Build', 'stability:', '1', 'out', 'of', 'the', 'last', '2', 'builds', 'failed.', '80', '40', '50']
if all(isinstance(i, int) for i in line[-3:]):
job_name = line[0]
warn = line[-3]
crit = line[-2]
score = line[-1]
if score < crit:
print ("CRITICAL - Health Score is %d" % score)
elif (score >= crit) and (score <= warn):
print ("WARNING - Health Score is %d" % score)
else:
print ("OK - Health Score is %d" % score)