True... technically, "Deletion of a name removes the binding of that name from the local or global namespace". Using `x.del()` can't do that.
That said, I would hazard to guess that `del x` is pretty rare (I have never felt the need for it myself). Ruby doesn't even have an equivalent operation, and doesn't seem to suffer as a result. If Python used methods instead of global functions for `len` and `del`, and provided a `delete_local_variable('x')` for these rare cases, that could have been a viable solution. So I still think it was a matter of preference rather than a pure technical consideration. But that's all second-guessing, anyway. You'd have to ask Guido what his reasoning was... On Mon, Oct 16, 2017 at 7:36 PM, Ned Batchelder <n...@nedbatchelder.com> wrote: > On 10/16/17 12:16 PM, Oren Ben-Kiki wrote: > >> 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"? >> > > It would still need to be a statement to allow for: > > del x > > since "x.del()" wouldn't affect the name x, it would affect the value x > refers to. > > --Ned. > > >> >> 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 > -- https://mail.python.org/mailman/listinfo/python-list