Run ❯
Get your
own Python
server
❯
Run Code
Ctrl+Alt+R
Change Orientation
Ctrl+Alt+O
Change Theme
Ctrl+Alt+D
Go to Spaces
Ctrl+Alt+P
y = 0 def myFunc(): global y y = 10 yield "Hello" y = 20 yield 51 y = 30 yield "Good Bye" #The function is called: x = myFunc() #But y is still 0: print("At this point, y is still:", y) #Run the first iteration: next(x) #And y becomes 10: print("Now, y is:", y) #Run another iteration: next(x) #And y becomes 20: print("Now, y is:", y) #Run another iteration: next(x) #And y becomes 30: print("Now, y is:", y)
At this point, y is still: 0
Now, y is: 10
Now, y is: 20
Now, y is: 30