Python iter()ฟังก์ชั่น
ตัวอย่าง
สร้างวัตถุ iterator และพิมพ์รายการ:
x = iter(["apple", "banana", "cherry"])
print(next(x))
print(next(x))
print(next(x))
ความหมายและการใช้งาน
ฟังก์ชันiter()
ส่งคืนอ็อบเจ็กต์ iterator
ไวยากรณ์
iter(object, sentinel)
ค่าพารามิเตอร์
Parameter | Description |
---|---|
object | Required. An iterable object |
sentinel | Optional. If the object is a callable object the iteration will stop when the returned value is the same as the sentinel |
หน้าที่เกี่ยวข้อง
ฟังก์ชันreversed()คืนค่าออบเจกต์ iterator ที่ย้อนกลับ