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 of print alist saying each thing in list print thing - each thing in list gets printed,

    ie cat, dog, cow.


Comments

Popular posts from this blog

How to access named pipes using JavaScript in Firefox add-on? -

multithreading - OPAL (Open Phone Abstraction Library) Transport not terminated when reattaching thread? -

node.js - req param returns an empty array -