On 02/26/2014 10:24 PM, ast wrote:
Hello
box is a list of 3 integer items
If I write:
box.sort()
if box == [1, 2, 3]:
the program works as expected. But if I write:
if box.sort() == [1, 2, 3]:
it doesn't work, the test always fails. Why ?
Thx
sort() sorts the sequence in pla
On 02/26/2014 10:24 PM, ast wrote:
Hello
box is a list of 3 integer items
If I write:
box.sort()
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 observi
Thanks for the very clear explanation
--
https://mail.python.org/mailman/listinfo/python-list
"ast" :
> if I write:
>
>if box.sort() == [1, 2, 3]:
>
> it doesn't work, the test always fails. Why ?
The list.sort() method returns None.
The builtin sorted() function returns a list:
if sorted(box) == [1, 2, 3]:
would work.
Note that the list.sort() method is often preferred because
"ast" writes:
> If I write:
>
>box.sort()
>if box == [1, 2, 3]:
>
> the program works as expected. But if I write:
>
>if box.sort() == [1, 2, 3]:
>
> it doesn't work, the test always fails. Why ?
Because very often methods **dont't** return the object they are applied
(self that is).
On Thu, Feb 27, 2014 at 07:24:24AM +0100, ast wrote:
> Hello
>
> box is a list of 3 integer items
>
> If I write:
>
>box.sort()
>if box == [1, 2, 3]:
>
>
> the program works as expected. But if I write:
>
>if box.sort() == [1, 2, 3]:
>
> it doesn't work, the test always fails. Wh
"ast" wrote in message
news:530eda1d$0$2061$426a7...@news.free.fr...
> Hello
>
> box is a list of 3 integer items
>
> If I write:
>
>box.sort()
>if box == [1, 2, 3]:
>
>
> the program works as expected. But if I write:
>
>if box.sort() == [1, 2, 3]:
>
> it doesn't work, the test alwa
Hello
box is a list of 3 integer items
If I write:
box.sort()
if box == [1, 2, 3]:
the program works as expected. But if I write:
if box.sort() == [1, 2, 3]:
it doesn't work, the test always fails. Why ?
Thx
--
https://mail.python.org/mailman/listinfo/python-list