6.2 列表的循环遍历

1. 使用for循环

为了更有效率的输出列表的每个数据,可以使用循环来完成

demo:

    namesList = ['xiaoWang','xiaoZhang','xiaoHua']    
    for name in namesList:        
        print(name)

结果:

    xiaoWang    
    xiaoZhang    
    xiaoHua

2. 使用while循环

为了更有效率的输出列表的每个数据,可以使用循环来完成

demo:

    namesList = ['xiaoWang','xiaoZhang','xiaoHua']    
    length = len(namesList)

    i = 0

    while i<length:        
        print(namesList[i])        
        i+=1

结果:

    xiaoWang    
    xiaoZhang    
    xiaoHua

results matching ""

    No results matching ""