Created
April 5, 2017 16:12
-
-
Save tranghaviet/d6e9862afe02553ef9063c5a2419fe8e to your computer and use it in GitHub Desktop.
yeild in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> def dummy(): | |
... print "You won't see me when created" | |
... yield 1 | |
... print "You didn't see me" | |
... yield 2 | |
... print "Bye bye" | |
... | |
>>> gen = dummy() | |
>>> gen.next() | |
You won't see me when created | |
1 | |
>>> gen.next() | |
You didn't see me | |
2 | |
# lần tạo gen = dummy() thì hàm chưa được thực thi | |
# lần gọi gen.next() tiếp theo thì chương trình sẽ được thực thi | |
# và chạy tiếp ở các yield tương ứng |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment