ลบค่าอยู่ในรายชื่อเป็นภาษาไพธอน

รหัสตัวอย่าง

87
0

ปลั๊กอินสำหรับไพธอนลบออกจากรายการอีลีเมนต์

myList.remove(item) # Removes first instance of "item" from myList
myList.pop(i) # Removes and returns item at myList[i]
14
0

ลบรายการจากรายการเป็นภาษาไพธอน

# removes item with given name in list
list = [15, 79, 709, "Back to your IDE"]
list.remove("Back to your IDE")

# removes last item in list
list.pop()

# pop() also works with an index...
list.pop(0)

# ...and returns also the "popped" item
item = list.pop()
13
0

ลบค่าอยู่ในรายชื่อเป็นภาษาไพธอน

list.remove(element)
10
0

ลบค่าจากภาษาไพธอนรายการโดยค่า

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

ปลั๊กอินสำหรับไพธอนเป็นไงเพื่อลบส่วนประกอบจากรายชื่อ

# Basic syntax:
my_list.remove(element)

# Note, .remove(element) removes the first matching element it finds in
# 	the list.

# Example usage:
animals = ['cat', 'dog', 'rabbit', 'guinea pig', 'rabbit']
animals.remove('rabbit')
print(animals)
--> ['cat', 'dog', 'guinea pig', 'rabbit'] # Note only 1st instance of
#	rabbit was removed from the list. 

# Note, if you want to remove all instances of an element, convert the
#	list to a set and back to a list, and then run .remove(element)	E.g.:
animals = list(set['cat', 'dog', 'rabbit', 'guinea pig', 'rabbit']))
animals.remove('rabbit')
print(animals)
--> ['cat', 'dog', 'guinea pig']
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]
>>> 

หน้าคล้ายกัน

คล้ายกันหน้ากับตัวอย่าง

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

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

ดังอยู่ในนี้หมวดหมู่

ดังหน้ากับตัวอย่างอยู่ในหมวดหมู่