Strange behavior with sort()
gary.herron at islandtraining.com
Thu Feb 27 08:16:27 CET 2014
On 02/26/2014 10:24 PM, ast wrote:
> box is a list of 3 integer items
> If I write:
> if box == [1, 2, 3]:
> the program works as expected. But if I write:
> if box.sort() == [1, 2, 3]:
Most such questions can be answered by printing out the values in
question and observing first hand what the value is.
So, print out box.sort() to see what it is. You might be surprised.
Hint: box.sort() does indeed cause box to be sorted, and the sorted list
is left in box, but the sorted list is not returned as a function value.
> it doesn't work, the test always fails. Why ?
More information about the Python-list