This is my piece of code with two generators defined:
one_line_gen = (x for x in range(3)) def three_line_gen(): yield 0 yield 1 yield 2
Because in One liner is Generator Object while the three liner is a function. They meant to be different.
Generator
function
These two are similar.
def three_line_gen_fun(): yield 0 yield 1 yield 2 three_line_gen = three_line_gen_fun() one_line_gen = (x for x in range(3)) type(three_line_gen) == type(one_line_gen)