1
1
1Tima12020-08-26 18:17:10
Python
1Tima1, 2020-08-26 18:17:10

Can the function be executed after returning a value?

The iterator passes the keys to the function.
if the key is present, 1 is displayed and the value is returned, then the
code
HE IS NOT IN THE ELIF OR ELSE block

, he does something. at the end prints let's say 2
adds the key and value to the dictionary.
and outputs the new value.

For some reason, this is my conclusion.
1
2
1
2
...

after the first return (where we output 1) , shouldn't the function break?
An important condition, the same argument is passed to the function.
If we passed the value to another function, then why continue to execute the code if there is nowhere to output the second return?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2020-08-26
@1Tima1

maybe. use yield to return one of the values, and the function will be an iterator (will run until it completes):

def test(x):
    for i in range(x):
        yield i
for n in test(10):
   print(n)

Each yield statement will suspend the execution of the function until the value has been processed.

S
Sergey Svetlov, 2020-08-27
@svetloffs

without code, it's hard to understand how your program actually works...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question