Movatterモバイル変換


[0]ホーム

URL:


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

Commitd992d27

Browse files
Added List copying
1 parentac33388 commitd992d27

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

‎jupyter_notebooks/05_Lists_and_Tuples.ipynb‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,40 @@
169169
"spam[:]"
170170
]
171171
},
172+
{
173+
"cell_type":"markdown",
174+
"metadata": {},
175+
"source": [
176+
"## Copying a List"
177+
]
178+
},
179+
{
180+
"cell_type":"code",
181+
"execution_count":1,
182+
"metadata": {},
183+
"outputs": [
184+
{
185+
"name":"stdout",
186+
"output_type":"stream",
187+
"text": [
188+
"[1, 2, 6]\n",
189+
"[1, 2, 6]\n"
190+
]
191+
}
192+
],
193+
"source": [
194+
"list1 = [1,2,3]\n",
195+
"#Don't\n",
196+
"copy1 = list1 # It will simply point the pointer of copy1 to list1 i.e. changes in copy1 appears in list1 also\n",
197+
"copy1[2] = 6\n",
198+
"print(list1)\n",
199+
"\n",
200+
"#Do - Slicing\n",
201+
"copy2 = list1[:] #It will copy every element of list1 to copy2\n",
202+
"copy2[1] = 5\n",
203+
"print(list1)"
204+
]
205+
},
172206
{
173207
"cell_type":"markdown",
174208
"metadata": {},
@@ -719,7 +753,7 @@
719753
"name":"python",
720754
"nbconvert_exporter":"python",
721755
"pygments_lexer":"ipython3",
722-
"version":"3.7.0"
756+
"version":"3.8.8"
723757
}
724758
},
725759
"nbformat":4,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp