why del is not a function or method?

Oren Ben-Kiki python-oren at ben-kiki.org
Mon Oct 16 12:16:54 EDT 2017


That doesn't explain why `del` isn't a method though. Intuitively,
`my_dict.delete(some_key)` makes sense as a method. Of course, you could
also make the same case for `len` being a method... and personally I think
it would have been cleaner that way in both cases. But it is a minor issue,
if at all.

I guess the answer is a combination of "historical reasons" and "Guido's
preferences"?


On Mon, Oct 16, 2017 at 6:58 PM, Stefan Ram <ram at zedat.fu-berlin.de> wrote:

> Xue Feng <xf.lotus at yahoo.com> writes:
> >I wonder why 'del' is not a function or method.
>
>   Assume,
>
> x = 2.
>
>   When a function »f« is called with the argument »x«,
>   this is written as
>
> f( x )
>
>   . The function never gets to see the name »x«, just
>   its boundee (value) »2«. So, it cannot delete the
>   name »x«.
>
>   Also, the function has no access to the scope of »x«,
>   and even more so, it cannot make any changes in it.
>
>   Therefore, even a call such as
>
> f( 'x' )
>
>   will not help much.
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list