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

▼ Show 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)))
Learn More with Madanswer

Related questions

0 votes
asked May 23, 2020 in Python by sharadyadav1986