As per the very first lesson on list, one needs to add the name of the animal. What if the length of the name is <3, will it get printed? I tried with "JO" and though the length is <3, still it got printed. Then I modified the code to print the length like this. zoo_animals = ["pangolin", "cassowary", "sloth", "jo"]; # One animal is missing! print(len(zoo_animals)) if len(zoo_animals) > 3: print "The first animal at the zoo is the " + zoo_animals print "The second animal at the zoo is the " + zoo_animals print "The third animal at the zoo is the " + zoo_animals print "The fourth animal at the zoo is the " + zoo_animals Though , the program is showing correctly the length of each of the animals, but if i modify the code without giving any reference such as : - print(len(zoo_animals)) the length is showing as 4. please explain.
This checks the number of items in the entire
list, which is
if len(zoo_animals) > 3:
Therefore, the condition is
True, so the
if block gets executed, and all the items get displayed, including
This displays the number of characters in the item with index
2, which is
5 should be displayed ...
I got this one finally. I thought len is actually checking the length of the index.....