Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 52073d8

Browse files
varian97Akuli
authored andcommitted
feat: Add list comprehension in list tutorial
1 parent 7e732f7 commit 52073d8

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

‎basics/lists-and-tuples.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,17 @@ We'll talk more about loops [in the next chapter](loops.md).
141141
>>>
142142
```
143143

144+
Another useful things about list is **comprehension**.
145+
**Comprehension** is a way to loop the list in single line. It makes our code more pythonic.
146+
147+
```python
148+
>>> numbers = [1,2,3,4,5]
149+
>>> numbers_squared = [ number ** 2 for number in numbers ]
150+
>>> numbers_squared
151+
[1, 4, 9, 16, 25]
152+
>>>
153+
```
154+
144155
We can also use slicing and indexing to change the content:
145156

146157
```python

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /