วิธี extend() ของ Python รายชื่อ
ตัวอย่าง
เพิ่มองค์ประกอบใน cars สู่ตาราง fruits
fruits = ['apple', 'banana', 'cherry'] cars = ['Porsche', 'BMW', 'Volvo'] fruits.extend(cars)
คำนำออกและวิธีใช้
extend() method adds the specified list elements (or any iterable elements) to the end of the current list.
ระบบที่ใช้
list.extend(iterable)
ค่าตัวแปร
ตัวแปร | การอธิบาย |
iterable | วัตถุประสงค์แนวหน้า。ทุกๆ วัตถุที่สามารถวนรวมได้ (รายชื่อ、ชุมชน、tuple และอื่น ๆ) |
ตัวอย่างเพิ่มเติม
ตัวอย่าง
เพิ่มtuple สู่ตาราง fruits
fruits = ['apple', 'banana', 'cherry'] points = (1, 4, 5, 9) fruits.extend(points)