We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 52073d8 commit 93a00c2Copy full SHA for 93a00c2
basics/lists-and-tuples.md
@@ -142,7 +142,7 @@ We'll talk more about loops [in the next chapter](loops.md).
142
```
143
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.
+**Comprehension** is a way to construct a list in single line. It makes our code more clean, shorter and easier to read.
146
147
```python
148
>>> numbers = [1,2,3,4,5]
@@ -152,6 +152,18 @@ Another useful things about list is **comprehension**.
152
>>>
153
154
155
+without comprehension:
156
+
157
+```python
158
+>>> numbers = [1,2,3,4,5]
159
+>>> numbers_squared = []
160
+>>> for number in numbers:
161
+... numbers_squared.append(number**2)
162
+>>> numbers_squared
163
+[1, 4, 9, 16, 25]
164
+>>>
165
+```
166
167
We can also use slicing and indexing to change the content:
168
169
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments