我们在使用for循环的时候,由于python语言的高效性,致使我们渐渐忽略了一个很重要的角色,index。
怎样查找当前记录的下一条记录呢?
li1 = [3, 4, 5, 6, 7]
i = 0
for rec in li1:
print "this record is: " + str(rec)
if i + 1 < len(li1):
print "next record is: " + str(li1[i + 1]
else:
print "the last record!"
print 'n'
i += 1 运行结果:
this record is: 3
next record is: 4
this record is: 4
next record is: 5
this record is: 5
next record is: 6
this record is: 6
next record is: 7
this record is: 7
the last record!
最后
以上就是勤奋花生最近收集整理的关于Python for循环之查找下一个记录的全部内容,更多相关Python内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复