Introduction to List


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!
if len(zoo_animals) > 3:
	print "The first animal at the zoo is the " + zoo_animals[0]
	print "The second animal at the zoo is the " + zoo_animals[1]
	print "The third animal at the zoo is the " + zoo_animals[2]
	print "The fourth animal at the zoo is the " + zoo_animals[3]

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 : - 


the length is showing as 4. 

please explain.


Hi @ratz199,

This checks the number of items in the entire zoo_animals list, which is 4 ...

if len(zoo_animals) > 3:

Therefore, the condition is True, so the if block gets executed, and all the items get displayed, including "jo".

This displays the number of characters in the item with index 2, which is "sloth", so 5 should be displayed ...



I got this one finally. I thought len is actually checking the length of the index.....