Do you know what Does The <Yield> Keyword Do In Python?
Submitted by: MuhammadThe <yield> keyword can turn any function into a generator. It works like a standard return keyword. But it’ll always return a generator object. Also, a function can have multiple calls to the <yield> keyword.
See the example below.
def testgen(index):
weekdays = ['sun','mon','tue','wed','thu','fri','sat']
yield weekdays[index]
yield weekdays[index+1]
day = testgen(0)
print next(day), next(day)
#output: sun mon
Submitted by: Muhammad
See the example below.
def testgen(index):
weekdays = ['sun','mon','tue','wed','thu','fri','sat']
yield weekdays[index]
yield weekdays[index+1]
day = testgen(0)
print next(day), next(day)
#output: sun mon
Submitted by: Muhammad
Read Online Python Developer Job Interview Questions And Answers
Top Python Developer Questions
☺ | Do you know what Is The Key Difference Between A List And The Tuple? |
☺ | Tell me how Does The Ternary Operator Work In Python? |
☺ | Do you know what Does The <Yield> Keyword Do In Python? |
☺ | Tell me what is PEP 8? |
☺ | Tell me what are the built-in type does python provides? |
Top Web Developer Categories
☺ | Bootstrap Interview Questions. |
☺ | Front End Web Developer Interview Questions. |
☺ | Typography Interview Questions. |
☺ | Laravel PHP Developer Interview Questions. |
☺ | Junior Developer PHP Interview Questions. |