python - Simple for loop explanation -
why code...
alist = ['cat','dog','cow'] item in alist: print alist
output
['cat', 'dog', 'cow'] ['cat', 'dog', 'cow'] ['cat', 'dog', 'cow']
while changing print
alist
item
outputs:
cat dog cow
i understand when printing alist print list many times there elements in list guess don't understand why different.
i grateful if explain difference me or point me in right direction.
- you have list - contains cat, dog, , cow.
- then say: each thing in list, print list.
- you have 3 things in list (cat, dog, , cow) list gets printed 3 times.
when switch statement
print item
instead ofprint alist
saying each thing in list print thing - each thing in list gets printed,ie
cat, dog, cow.
Comments
Post a Comment