Last active
July 1, 2016 20:16
-
-
Save rahulkp220/f770279ec83e15f7211b61cb4e4681e6 to your computer and use it in GitHub Desktop.
Describes how yield from keyword works and behaves in Python3
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
""" while reading about yield keyword, I got curious about the difference between a yield and a yield from keywords. | |
Here is a brief differentiation that I have shown. | |
""" | |
#a normal yield inside a function that takes a list as an input | |
def a_func(my_list): | |
yield my_list | |
#using yield from keyword on a similar function | |
def b_func(my_list): | |
yield from my_list | |
#the difference is evident when we iterate over these functions, let's see. | |
for a in a_func(["rahul","lakhanpal']): | |
print(a) | |
#gives output | |
["rahul","lakhanpal"] | |
for b in b_func(["rahul","lakhanpal"]): | |
print(b) | |
#gives output | |
rahul | |
lakhanpal | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment