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

1 Answer

0 votes
by
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
0 votes
asked Feb 5 in Angular by SakshiSharma
...