“rendement python de” Réponses codées

rendement python de

# In python construction 'yield from something' is just 
# the abbreviation of 'for i in something: yield i'
# So, we can change this:
def yieldOnly():
    yield "A"
    yield "B"
    yield "C"

def yieldFrom():
    for _ in [1, 2, 3]:
        yield from yieldOnly()

test = yieldFrom()
for i in test:
    print(i)
    
# to this:

def yieldOnly():
    yield "A"
    yield "B"
    yield "C"

def yieldFrom():
    for _ in [1, 2, 3]:
        for i in yieldOnly():
            yield i

test = yieldFrom()
for i in test:
    print(i)
Jittery Jay

Donner des expressions en python

yield_atom       ::=  "(" yield_expression ")"
yield_expression ::=  "yield" [expression_list | "from" expression]


#Using the yield operation in functions
def gen():  # defines a generator function
    yield 123

async def agen(): # defines an asynchronous generator function
    yield 123
LazFlex

Réponses similaires à “rendement python de”

Questions similaires à “rendement python de”

Plus de réponses similaires à “rendement python de” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code