generator expressionproduces items parens are often optional { for in range( ){ set comprehension and {xyis set in these versions too {xx for in range( )dictionary comprehension and { scopes and comprehension variables now that we've seen all comprehension formsbe sure to also review ' overview of the localization of loop variables in these expressions python localizes loop variables in all four forms--temporary loop variable names in generatorsetdictionaryand list comprehensions are local to the expression they don' clash with names outsidebut are also not available thereand work differently than the for loop iteration statementc:\codepy - ( for in range( )at nameerrorname 'xis not defined [ for in range( )[ for in range( )pass xgeneratorsetdictand list localize but loop statements do not localize names as mentioned in variables assigned in comprehension are really further nested special-case scopeother names referenced within these expressions follow the usual legb rules in the following generatorfor examplez is localized in the comprehensionbut and are found in the enclosing local and global scopes as usualx 'aaadef func() 'bbbprint('join( for in ) comprehensiony localx global func(aaabbb python is the same in this regardexcept that list comprehension variables are not localized--they work just like for loops and keep their last iteration valuesbut are also comprehension syntax summary