Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def yield_demo(n):
- for j in range(n):
- yield triple(j)
- print("j is:", j)
- print("end of yield_demo")
- def triple(m):
- print("inside triple call", m)
- return m*3
- for i in yield_demo(5):
- print("i is:", i)
- ## output looks like the following
- # inside triple call 0
- # i is: 0
- # j is: 0
- # inside triple call 1
- # i is: 3
- # j is: 1
- # inside triple call 2
- # i is: 6
- # j is: 2
- # inside triple call 3
- # i is: 9
- # j is: 3
- # inside triple call 4
- # i is: 12
- # j is: 4
- # end of yield_demo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement