generator' code location the net effect is much like that of generator functionsbut in the context of comprehension expressionwe get back an object that remembers where it left off after each part of its result is returned also like generator functionslooking under the hood at the protocol that these objects automatically support can help demystify themthe iter call is again not required at the top herefor reasons we'll expand on aheadg ( * for in range( )iter(gis true next( next( next( next( next(gtraceback (most recent call last)file ""line in stopiteration iter(goptional__iter__ returns self generator objectsautomatic methods at againwe don' typically see the next iterator machinery under the hood of generator expression like this because for loops trigger it for us automaticallyfor num in ( * for in range( ))print('% % (numnum )calls next(automatically as we've already learnedevery iteration context does this--including for loopsthe summapand sorted built-in functionslist comprehensionsand other iteration contexts we learned about in such as the anyalland list built-in functions as iterablesgenerator expressions can appear in any of these iteration contextsjust like the result of generator function call for examplethe following deploys generator expressions in the string join method call and tuple assignmentiteration contexts both in the first test herejoin runs the generator and joins the substrings it produces with nothing between--to simply concatenate'join( upper(for in 'aaa,bbb,cccsplit(',')'aaabbbcccabc ( '\nfor in 'aaa,bbb,cccsplit(',') comprehensions and generations