Dec 19, 2019 in Python
Q: What Is The Syntax For Generator Expression In Python?

1 Answer

Dec 19, 2019
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)))
Click here to read more about Python
Click here to read more about Insurance

Related questions

May 23 in Python
Aug 29 in Python
Feb 6 in JavaScript