diff --git a/notebooks/beginner/notebooks/lists.ipynb b/notebooks/beginner/notebooks/lists.ipynb index 0a08876..f46fd34 100644 --- a/notebooks/beginner/notebooks/lists.ipynb +++ b/notebooks/beginner/notebooks/lists.ipynb @@ -147,6 +147,31 @@ "print('original: {}, modified: {}'.format(original, modified))" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Copying a list" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "list1 = [1,2,3]\n", + "#Don't\n", + "copy1 = list1 # It will simply point the pointer of copy1 to list1 i.e. changes in copy1 appears in list1 also\n", + "copy1[2] = 6\n", + "print(list1)\n", + "\n", + "#Do - Slicing\n", + "copy2 = list1[:] #It will copy every element of list1 to copy2\n", + "copy2[1] = 5\n", + "print(list1)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -310,7 +335,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.4" + "version": "3.8.8" } }, "nbformat": 4,