How to check iteration through list = No?

How to verify that the iteration will not be exceeded None? I wrote the following code:

async def foo(categories: list=None):
    for category in categories or []:

Is this a good way, or can I somehow avoid checking or []at each iteration?

+4
source share
1 answer

Let me check it out.

def foo():
    print('In foo')
    return range(5)

Now, if I call ( ) fooat the beginning of the loop , it should print as many times as it is called / evaluated.forfor _ in foo()In foo

So,

for _ in foo():
    pass

In foo

And is called only once. The value was evaluated only once.

+2
source

Source: https://habr.com/ru/post/1692205/


All Articles