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 <r...@zedat.fu-berlin.de> wrote: > Xue Feng <xf.lo...@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 > -- https://mail.python.org/mailman/listinfo/python-list