in Python by
What Is The Syntax For Generator Expression In Python?

1 Answer

0 votes
The syntax for generator expression matches with the list comprehension, but the difference is that it uses parenthesis:

( expression(var) for var in iterable )

For example, the below code will create a generator object that generates the values from 10 to 20 upon using it.

>>> (var for var in range(10, 20))

 at 0x0000000003668728>

>>> list((var for var in range(10, 20)))

Related questions

0 votes
asked May 23, 2020 in Python by sharadyadav1986
+2 votes
asked Jan 1, 2022 in Python by sharadyadav1986
0 votes
asked Jan 11, 2021 in Python by SakshiSharma