Yield in Python

Yield – Instead of return can use this, It returns as a generator object, Mainly designed for memory consumption

ip = [1,2,3,4,5]
def test(ip):
    ts = sum(ip)
    for x in range(len(ip)):
        yield ts-ip[x]
print (min(test(ip))) #10
print (max(test(ip))) #14

Leave a comment