Python‎ > ‎operator‎ > ‎

operator.delitem()

http://www.adilwaseem.com/

Return
The method will delete the item as del a(b).

Syntax
operator.delitem(a, b)-> delete the item
__delitem__

Parameters
a=list
b=index number

Import module
Importing module is required in the Shell window and the Editor window.

Examples
The method deleted the item in list.
 >>> a=[1,3,5]
>>> operator.delitem(a,1)
>>> a
[1, 5]
>>> operator.delitem(a,1)
>>> a
[1]

del a[b]
The method perform same function as operator.delitem(a, b).
 >>> a=[1,3,5,7,9]
>>> del a[2]
>>> a
[1, 3, 7, 9]

Operator.__delitem__(a,b)
The method returns the same function as operator.delitem(a,b).
 >>> a=[1, 3, 7, 9]
>>> operator.__delitem__(a,2)
>>> a
[1, 3, 9]


Limitation
The method does not support tuple.
 >>> a=(1,3,5,7)
>>> operator.delitem(a, 3)
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
operator.delitem(a, 3)
TypeError: 'tuple' object doesn't support item deletion


Comments