एक सूची पायथन से एक मान ड्रॉप करें

कोड उदाहरण

13
0

सूची पायथन में एक मान हटाएं

list.remove(element)
10
0

मूल्य से पायथन सूची से मूल्य निकालें

>>> a = ['a', 'b', 'c', 'd']
>>> a.remove('b')
>>> print a
['a', 'c', 'd']
3
0

सूची पायथन में निकालें

# animals list
animals = ['cat', 'dog', 'rabbit', 'guinea pig']

# 'rabbit' is removed
animals.remove('rabbit')

# Updated animals List
print('Updated animals list: ', animals)
3
0

सूची मान से तत्व हटाएं

>>> a=[1,2,3]
>>> a.remove(2)
>>> a
[1, 3]
>>> a=[1,2,3]
>>> del a[1]
>>> a
[1, 3]
>>> a= [1,2,3]
>>> a.pop(1)
2
>>> a
[1, 3]
>>> 
2
0

पायथन सूची से मूल्य निकालें

# Below are examples of 'remove', 'del', and 'pop' 
#   methods of removing from a python list
""" 'remove' removes the first matching value, not a specific index: """
>>> a = [0, 2, 3, 2]
>>> a.remove(2)
>>> a
[0, 3, 2]

""" 'del' removes the item at a specific index: """
>>> a = [9, 8, 7, 6]
>>> del a[1]
>>> a
[9, 7, 6]

""" 'pop' removes the item at a specific index and returns it. """
>>> a = [4, 3, 5]
>>> a.pop(1)
3
>>> a
[4, 5]

""" Their error modes are different too: """
>>> a = [4, 5, 6]
>>> a.remove(7)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: list.remove(x): x not in list
>>> del a[7]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list assignment index out of range
>>> a.pop(7)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: pop index out of range

इसी तरह के पन्ने

उदाहरणों के साथ समान पृष्ठ

अन्य भाषाओं में

यह पृष्ठ अन्य भाषाओं में है

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................