Python ระบุ ()ฟังก์ชั่น
ตัวอย่าง
แปลง tuple เป็นอ็อบเจ็กต์ที่แจกแจง:
x = ('apple', 'banana', 'cherry')
y = enumerate(x)
ความหมายและการใช้งาน
ฟังก์ชันenumerate()
รับคอลเล็กชัน (เช่น ทูเพิล) และส่งกลับเป็นอ็อบเจกต์ที่แจกแจง
ฟังก์ชันenumerate()
เพิ่มตัวนับเป็นคีย์ของวัตถุที่แจกแจง
ไวยากรณ์
enumerate(iterable, start)
ค่าพารามิเตอร์
Parameter | Description |
---|---|
iterable | An iterable object |
start | A Number. Defining the start number of the enumerate object. Default 0 |