请您参考如下方法:
if len(a) > 4:
# list contains fourth element, a[4]
或
try:
a[4] # do something with a[4]
except IndexError:
print "there is no element a[4]"
请您参考如下方法:
if len(a) > 4:
# list contains fourth element, a[4]
或
try:
a[4] # do something with a[4]
except IndexError:
print "there is no element a[4]"