python 迭代工具

names = ['anne', 'beth', 'george', 'damon']
ages = [12, 45, 32, 102]

for name,age in zip(names,ages):
    #print('name:'+ name + ',ages:' + str(age))
    print("name:",name,"ages:",age)

result:

name: anne ages: 12
name: beth ages: 45
name: george ages: 32
name: damon ages: 102

 

example2:

a = ['aaa','bbb','ccc','ddd']
for index, aaa in enumerate(a):
    if 'aaa' in aaa:
        a[index] = 'bbb'

print(a)

result :

['bbb', 'bbb', 'ccc', 'ddd']

 

上一篇:linux的指令


下一篇:list找相同的个数