|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "metadata": {}, |
| 5 | + "cell_type": "markdown", |
| 6 | + "source": [ |
| 7 | + "### Interning \n", |
| 8 | + "\n", |
| 9 | + "- special feature in python to store value for references due to reusing values\n", |
| 10 | + "- only for immutable types and short strings without spaces\n", |
| 11 | + "- for number in range from -5 to 256" |
| 12 | + ], |
| 13 | + "id": "c5aceec3ddf7ec8f" |
| 14 | + }, |
| 15 | + { |
| 16 | + "metadata": { |
| 17 | + "ExecuteTime": { |
| 18 | + "end_time": "2024-11-18T15:01:13.855733Z", |
| 19 | + "start_time": "2024-11-18T15:01:13.848940Z" |
| 20 | + } |
| 21 | + }, |
| 22 | + "cell_type": "code", |
| 23 | + "source": [ |
| 24 | + "x = [[1, 2], [3, 4]]\n", |
| 25 | + "\n", |
| 26 | + "y = x\n", |
| 27 | + "print(x == y, x is y )" |
| 28 | + ], |
| 29 | + "id": "96d804d0b04a667", |
| 30 | + "outputs": [ |
| 31 | + { |
| 32 | + "name": "stdout", |
| 33 | + "output_type": "stream", |
| 34 | + "text": [ |
| 35 | + "True True\n" |
| 36 | + ] |
| 37 | + } |
| 38 | + ], |
| 39 | + "execution_count": 2 |
| 40 | + }, |
| 41 | + { |
| 42 | + "metadata": { |
| 43 | + "ExecuteTime": { |
| 44 | + "end_time": "2024-11-18T15:01:46.205182Z", |
| 45 | + "start_time": "2024-11-18T15:01:46.199591Z" |
| 46 | + } |
| 47 | + }, |
| 48 | + "cell_type": "code", |
| 49 | + "source": [ |
| 50 | + "x[0][0] = 42\n", |
| 51 | + "print(x, y)" |
| 52 | + ], |
| 53 | + "id": "7c65c216a371c326", |
| 54 | + "outputs": [ |
| 55 | + { |
| 56 | + "name": "stdout", |
| 57 | + "output_type": "stream", |
| 58 | + "text": [ |
| 59 | + "[[42, 2], [3, 4]] [[42, 2], [3, 4]]\n" |
| 60 | + ] |
| 61 | + } |
| 62 | + ], |
| 63 | + "execution_count": 3 |
| 64 | + }, |
| 65 | + { |
| 66 | + "metadata": { |
| 67 | + "ExecuteTime": { |
| 68 | + "end_time": "2024-11-18T15:25:56.883231Z", |
| 69 | + "start_time": "2024-11-18T15:25:56.866838Z" |
| 70 | + } |
| 71 | + }, |
| 72 | + "cell_type": "code", |
| 73 | + "source": [ |
| 74 | + "z = x.copy()\n", |
| 75 | + "print(z == x, z is x)\n", |
| 76 | + "z[0][0] = 1024\n", |
| 77 | + "print(x, y, z)\n", |
| 78 | + "z[0] = [42, 2]\n", |
| 79 | + "print(x, y, z)\n", |
| 80 | + "z[-1] = x[0]\n", |
| 81 | + "x[0][0] = 666\n", |
| 82 | + "print(x, y, z)" |
| 83 | + ], |
| 84 | + "id": "f19b914781970f9d", |
| 85 | + "outputs": [ |
| 86 | + { |
| 87 | + "name": "stdout", |
| 88 | + "output_type": "stream", |
| 89 | + "text": [ |
| 90 | + "True False\n", |
| 91 | + "[[1024, 2], [3, 4]] [[1024, 2], [3, 4]] [[1024, 2], [3, 4]]\n", |
| 92 | + "[[1024, 2], [3, 4]] [[1024, 2], [3, 4]] [[42, 2], [3, 4]]\n", |
| 93 | + "[[666, 2], [3, 4]] [[666, 2], [3, 4]] [[42, 2], [666, 2]]\n" |
| 94 | + ] |
| 95 | + } |
| 96 | + ], |
| 97 | + "execution_count": 8 |
| 98 | + }, |
| 99 | + { |
| 100 | + "metadata": {}, |
| 101 | + "cell_type": "markdown", |
| 102 | + "source": [ |
| 103 | + "# functions parametrers order :\n", |
| 104 | + "- 1/positional\n", |
| 105 | + "- 2/*args -> tuple\n", |
| 106 | + "- 3/named\n", |
| 107 | + "- 4/optional / default\n", |
| 108 | + "- 5/**kwargs -> dictionary" |
| 109 | + ], |
| 110 | + "id": "ffedd48e3587e947" |
| 111 | + }, |
| 112 | + { |
| 113 | + "metadata": {}, |
| 114 | + "cell_type": "code", |
| 115 | + "outputs": [], |
| 116 | + "execution_count": null, |
| 117 | + "source": "", |
| 118 | + "id": "beb32861c2e33d67" |
| 119 | + } |
| 120 | + ], |
| 121 | + "metadata": { |
| 122 | + "kernelspec": { |
| 123 | + "display_name": "Python 3", |
| 124 | + "language": "python", |
| 125 | + "name": "python3" |
| 126 | + }, |
| 127 | + "language_info": { |
| 128 | + "codemirror_mode": { |
| 129 | + "name": "ipython", |
| 130 | + "version": 2 |
| 131 | + }, |
| 132 | + "file_extension": ".py", |
| 133 | + "mimetype": "text/x-python", |
| 134 | + "name": "python", |
| 135 | + "nbconvert_exporter": "python", |
| 136 | + "pygments_lexer": "ipython2", |
| 137 | + "version": "2.7.6" |
| 138 | + } |
| 139 | + }, |
| 140 | + "nbformat": 4, |
| 141 | + "nbformat_minor": 5 |
| 142 | +} |
0 commit comments