On Apr 14, 2005, at 14:14, Ben Markwell wrote:

Could somebody explain to me why the code I used to complete this exercise doesn't work.
And how do you send an integer to len?

Well, I think you've successfully completed that exercise. len() doesn't work on integers because integers don't have a length.


Think of it that way:
- "foo" is a string of length 3 (it contains 3 elements (characters))
- [1, 2, 3] is a list of length 3 (it contains 3 elements)
- {'a': 1, 'b': 2, 'foo': 5} is a dict of length 3 (it contains 3 elements)
- 100 is an integer. How, as a human being, would you define its "length"? How many elements does it contain? It doesn't make sense, does it?


Well, you have it. Numbers (ints, floats...) don't have a length. Therefore, calling len() on an integer is a non-sense that results in an exception.

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting and sweating as you run through my corridors... How can you challenge a perfect, immortal machine?"



_______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor

Reply via email to