รายการ Python ป๊อป ()วิธีการ
ตัวอย่าง
ลบองค์ประกอบที่สองของfruit
รายการ:
fruits = ['apple', 'banana', 'cherry']
fruits.pop(1)
ความหมายและการใช้งาน
วิธี การpop()
ลบองค์ประกอบที่ตำแหน่งที่ระบุ
ไวยากรณ์
list.pop(pos)
ค่าพารามิเตอร์
Parameter | Description |
---|---|
pos | Optional. A number specifying the position of the element you want to remove, default value is -1, which returns the last item |
ตัวอย่างเพิ่มเติม
ตัวอย่าง
ส่งคืนองค์ประกอบที่ถูกลบ:
fruits = ['apple', 'banana', 'cherry']
x =
fruits.pop(1)
หมายเหตุ: วิธี การpop()
คืนค่าที่ลบออก