Why is del(ete) a statement instead of a method?

Simon Brunning SBrunning at trisystems.co.uk
Wed Oct 9 05:46:08 EDT 2002


> From:	Padraig Brady [SMTP:Padraig at Linux.ie]
> 
> Greg Brunet wrote:
> > I'm just trying to learn Python, and one thing that struck me as odd
> > was that to delete a specific list element, I need to use a statement
> > instead of a method like I use for almost everything else I do on the
> > list.  This seems a bit inconsistent.  Why wouldn't it be a method?
> > 
> 
> Being a python newbie myself this strck me as a little inconsistent.
> 
> why can't you do:
> 
> l=[1,2,3]
> s="123"
> i=123
> 
> l[1].del()
> l.del()
> s.del()
> i.del()
 
del doesn't do anything to the object at all - it is operating on the name,
removing it from the local namespace. Since it is operating on the name
rather than the object itself, making it a method of the object would be
inappropriate.
 
> Same goes for len() et. al.
 
Now here you might have a point...

Cheers,
Simon Brunning
TriSystems Ltd.
sbrunning at trisystems.co.uk




-----------------------------------------------------------------------
The information in this email is confidential and may be legally privileged.
It is intended solely for the addressee. Access to this email by anyone else
is unauthorised. If you are not the intended recipient, any disclosure,
copying, distribution, or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot
accept liability for statements made which are clearly the senders own.




More information about the Python-list mailing list