Skip to content

Instantly share code, notes, and snippets.

@rahulkp220
Last active July 1, 2016 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahulkp220/f770279ec83e15f7211b61cb4e4681e6 to your computer and use it in GitHub Desktop.
Save rahulkp220/f770279ec83e15f7211b61cb4e4681e6 to your computer and use it in GitHub Desktop.
Describes how yield from keyword works and behaves in Python3
""" 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