【划重点】Python遍历列表的四种方法
一、通过for循环直接遍历
user1 = ["宋江","林冲","卢俊义","吴用"] for user in user1: print(user)
二、通过range函数
user1 = ["宋江","林冲","卢俊义","吴用"] for i in range(len(user1)): print(i, user1[i])
三、通过iter迭代器
user1 = ["宋江","林冲","卢俊义","吴用"] for x in iter(user1): print(x)
四、通过enumerate函数
user1 = ["宋江","林冲","卢俊义","吴用"] for col,field in enumerate(user1): print(col,field)
五、准备睡觉了