why does list's .remove() does not return an object?
Jach Fong
jfong at ms4.hinet.net
Thu May 17 05:12:01 EDT 2018
Abdur-Rahmaan Janhangeer at 2018/5/17 PM 04:23 wrote:
> if then a more convenient way might be found to naturally remove and return
> the list
>
> maybe it was not included as one might want to remove the list only
>
> x = [1]
> x.remove(1)
>
> as opposed to
>
> x = [1]
> x.remove(1)
> new_list = x
IMO, this way is more flexible on its usage and avoid
a redundant copy.
--Jach
>
> i was looking for like
>
> x = [1]
> x.remove(1).return()
>
> ps. list is was demo illustrative var
>
> Abdur-Rahmaan Janhangeer
> https://github.com/Abdur-rahmaanJ
>
> On Thu, 17 May 2018, 07:01 Ned Batchelder, <ned at nedbatchelder.com> wrote:
>
>> On 5/16/18 10:41 PM, Abdur-Rahmaan Janhangeer wrote:
>>> why is x = list.remove(elem) not return the list?
>>>
>>>
>> Methods in Python usually do one of two things: 1) mutate the object and
>> return None; or 2) leave the object alone and return a new object. This
>> helps make it clear which methods mutate and which don't. Since .remove
>> mutates the list, it returns None.
>>
>> --Ned.
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
More information about the Python-list
mailing list