in Python by
What Is The Syntax For List Comprehension In Python?

1 Answer

0 votes
by
The signature for the list comprehension is as follows:

[ expression(var) for var in iterable ]

For example, the below code will return all the numbers from 10 to 20 and store them in a list.

>>> alist = [var for var in range(10, 20)]

>>> print(alist)

Related questions

0 votes
asked Dec 19, 2019 in Python by sharadyadav1986
0 votes
asked Jun 28, 2020 in Python by Robindeniel
0 votes
asked May 17, 2020 in Python by SakshiSharma
...