why del is not a function or method?
bartc
bc at freeuk.com
Mon Oct 16 12:07:31 EDT 2017
On 16/10/2017 16:58, Stefan Ram 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.
What about del team[2]?
There is no name involved here, and even a reference to team[2] won't help.
Presumably there is no other way to do an in-place deletion of an
element of a list. (Inserting an element is different.)
--
Bartc
More information about the Python-list
mailing list