Categories

Dec 19, 2019 in Python
Q: What Is The Syntax For List Comprehension In Python?

1 Answer

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

Related questions

Madanswer
May 16 in Python
May 17 in Python
Aug 30 in Python
...