For creating the iterator functions, Dev and QA testing services utilizing Python creates a special function to return iterator object. A ‘Yield’ statement is used in generator function instead of return.
Below is the syntax:
def newGenerator(): print('Here is item1') yield 10
print(‘Here is item2') yield 20
print('Here is item3') yield 30
The difference between yield statement and return statement is that the ‘yield’ pauses a function and continues later on calls whereas the ‘return’ terminates function. Also, the generators can be used directly with loops.
The Best Software Testing Services Company - QASource
QASource is the leading software app testing company that provides comprehensive and custom software testing solutions. Get started today with a free…
Replies
For creating the iterator functions, Dev and QA testing services utilizing Python creates a special function to return iterator object.
A ‘Yield’ statement is used in generator function instead of return.
Below is the syntax:
def newGenerator():
print('Here is item1')
yield 10
print(‘Here is item2')
yield 20
print('Here is item3')
yield 30
The difference between yield statement and return statement is that the ‘yield’ pauses a function and continues later on calls whereas the ‘return’ terminates function.
Also, the generators can be used directly with loops.