在使用python3时,有【并行迭代】与【按索引迭代】,并行迭代相对来说好理解,现在介绍下【按索引迭代】。...废话不多,直接上实例
# Demo:并行迭代 zip函数names = ["anne","beth","george","damon","bob"]ages = [12,45,32,102,101,103...按索引迭代案例按索引迭代方式一strings = ["Alice","Bob","Nick"]# strings[1] = "leo" #测试给列表添加元素后,的效果# print(strings)index... if "ob" in string: strings[index] = "Tom" # 将含有“ob”的元素,替换为Tom index += 1print(strings)按索引迭代方式二