Python | Loop With List

python loop with list
python loop with list

Loop With List


for  Loop

print the all item one by one using for loop



Example

    list = [ 'mango' , 'apple', 'kiwi' ]

    for  x in list :

        print(x)        


Output

    mango 

    apple

    kiwi



While Loop

print the all item one by one using While loop

use the len() function to get length of list, list index start from Zero and print the item one bye based on index 

set loop start from zero


Example

    list = [ 'mango' , 'apple', 'kiwi' ]

    i = 0

    while i < len(list):

        print(list[i])        

        i = i + 1;


Output

    mango 

    apple

    kiwi


Post a Comment (0)
Previous Post Next Post