[Tutor] Question regarding the len function of a list while using a
benmarkwell at gmail.com
Thu Apr 14 14:14:12 CEST 2005
Could somebody explain to me why the code I used to complete this exercise
And how do you send an integer to len?
*As an exercise, write a loop that traverses a list and prints the length of
each element. What happens if you send an integer to len?
*>>> foo = ['spam!', 1, ['brie', 'cheddar', 'swiss'], [1, 2, 3]]
>>> i = 0
>>> while i < len(foo):
i = i+1
Traceback (most recent call last):
File "<pyshell#28>", line 2, in -toplevel-
TypeError: len() of unsized object
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor