ID EN
Itertools

repeat

Python 3.11 🇮🇩 Bahasa Indonesia

Buat iterator yang mengembalikan objek berulang kali. Berjalan tanpa batas waktu kecuali argumen waktu ditentukan.

Syntax

PYTHON
itertools.repeat(object[, times])

Contoh

Example 1
PYTHON
def repeat(object, times=None):
     repeat(10, 3) --> 10 10 10
    if times is None:
        while True:
            yield object
    else:
        for i in range(times):
            yield object
Example 2
PYTHON
>>> list(map(pow, range(10), repeat(2)))
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]