On 3/3/21 3:23 PM, Hans Ginzel wrote:
> Please, is there a reason why extend() method does not return self?
>
>>>> a = [1,2].extend((3,4))
>>>> a
>>>> type(a)
> <class 'NoneType'>
>>>> b = [1,2]
>>>> b.extend((3,4))
>>>> b
> [1, 2, 3, 4] 

I think it just the general principle that mutating methods return None,
while methods that create a new object return that object.

Thus you use the return type if you expect a new object, and getting
None alerts you to the fact that it mutated the original instead of just
makeing a new object for the answer.

-- 
Richard Damon
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/DJWSWQQCPTKDXE3EKVTUWESI44QMFZU7/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to