“Python -Liste Pop vs entfernen” Code-Antworten

Python -Liste Pop vs entfernen

>>> a = [9, 8, 7, 6]
>>> del a[1]
>>> a
[9, 7, 6]
Glorious Gorilla

Pop vs Python entfernen

"diffrence between 'remove()','pop()' and 'del list[]' functions"
# list.remove()
*It only removes the object it does not bother about indexing.
# list.pop()
* pop removes specific index,also it returns object back.
# del list[]
*it can remove the index and object in it also entire list can be deleted.
#definition of each of the list function concludes some diffrences in them.
*'remove' deals with object while 'pop' and 'del' do focus on index.
*'pop' could return the deleted value of index while 'del' can not.
#These functions are aplicable at list not sequence like tuple.
Gr@Y_orphan_ViLL@in##

Python -Liste Pop vs entfernen

>>> a = [4, 3, 5]
>>> a.pop(1)
3
>>> a
[4, 5]
Glorious Gorilla

Python -Liste Pop vs entfernen

>>> a = [0, 2, 3, 2]
>>> a.remove(2)
>>> a
[0, 3, 2]
Glorious Gorilla

Python -Liste Pop vs entfernen

my_list = ['p','r','o','b','l','e','m']
my_list.remove('p')

# Output: ['r', 'o', 'b', 'l', 'e', 'm']
print(my_list)

# Output: 'o'
print(my_list.pop(1))

# Output: ['r', 'b', 'l', 'e', 'm']
print(my_list)

# Output: 'm'
print(my_list.pop())

# Output: ['r', 'b', 'l', 'e']
print(my_list)

my_list.clear()

# Output: []
print(my_list)
David Cao

Ähnliche Antworten wie “Python -Liste Pop vs entfernen”

Fragen ähnlich wie “Python -Liste Pop vs entfernen”

Weitere verwandte Antworten zu “Python -Liste Pop vs entfernen” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen