filmov
tv
#48 Python Tutorial for Beginners | List Comprehension in Python

Показать описание
List comprehensions provide a concise and elegant way to create lists.
List comprehension is more compact and faster than normal functions and loops for creating list.
We can create lists just like mathematical statements and in one line only.
The list comprehension always returns a result list.
Syntax:
It consists of brackets containing an expression followed by a for clause, then zero or more for or if clauses. The expressions can be anything, meaning you can put in all kinds of objects in lists.
The result will be a new list resulting from evaluating the expression.
A list comprehension generally consists of these parts :
1. Output expression,
2. input sequence,
3. a variable representing a member of the input sequence and an optional predicate part.
[ expression for item in list if conditional ]
Above Syntax is equivalent to:
for item in list:
if conditional:
expression
For detail watch the video.
To support me please subscribe my channel
Write your queries at:
Please like, comment, share and subscribe.
#daneyallari #python #pythonByDaneyalLari
List comprehension is more compact and faster than normal functions and loops for creating list.
We can create lists just like mathematical statements and in one line only.
The list comprehension always returns a result list.
Syntax:
It consists of brackets containing an expression followed by a for clause, then zero or more for or if clauses. The expressions can be anything, meaning you can put in all kinds of objects in lists.
The result will be a new list resulting from evaluating the expression.
A list comprehension generally consists of these parts :
1. Output expression,
2. input sequence,
3. a variable representing a member of the input sequence and an optional predicate part.
[ expression for item in list if conditional ]
Above Syntax is equivalent to:
for item in list:
if conditional:
expression
For detail watch the video.
To support me please subscribe my channel
Write your queries at:
Please like, comment, share and subscribe.
#daneyallari #python #pythonByDaneyalLari