|
18 | 18 | "print(thistuple)"
|
19 | 19 | ]
|
20 | 20 | },
|
| 21 | + { |
| 22 | + "cell_type": "code", |
| 23 | + "execution_count": 2, |
| 24 | + "metadata": {}, |
| 25 | + "outputs": [ |
| 26 | + { |
| 27 | + "name": "stdout", |
| 28 | + "output_type": "stream", |
| 29 | + "text": [ |
| 30 | + "()\n" |
| 31 | + ] |
| 32 | + } |
| 33 | + ], |
| 34 | + "source": [ |
| 35 | + "empty_tuple = () \n", |
| 36 | + "print (empty_tuple) " |
| 37 | + ] |
| 38 | + }, |
| 39 | + { |
| 40 | + "cell_type": "code", |
| 41 | + "execution_count": 3, |
| 42 | + "metadata": {}, |
| 43 | + "outputs": [ |
| 44 | + { |
| 45 | + "name": "stdout", |
| 46 | + "output_type": "stream", |
| 47 | + "text": [ |
| 48 | + "('python', 'geeks')\n" |
| 49 | + ] |
| 50 | + } |
| 51 | + ], |
| 52 | + "source": [ |
| 53 | + "tup = ('python', 'geeks') \n", |
| 54 | + "print(tup) " |
| 55 | + ] |
| 56 | + }, |
| 57 | + { |
| 58 | + "cell_type": "code", |
| 59 | + "execution_count": 4, |
| 60 | + "metadata": {}, |
| 61 | + "outputs": [ |
| 62 | + { |
| 63 | + "name": "stdout", |
| 64 | + "output_type": "stream", |
| 65 | + "text": [ |
| 66 | + "(0, 1, 2, 3, 'python', 'geek')\n" |
| 67 | + ] |
| 68 | + } |
| 69 | + ], |
| 70 | + "source": [ |
| 71 | + "tuple1 = (0, 1, 2, 3) \n", |
| 72 | + "tuple2 = ('python', 'geek') \n", |
| 73 | + " \n", |
| 74 | + "print(tuple1 + tuple2) " |
| 75 | + ] |
| 76 | + }, |
| 77 | + { |
| 78 | + "cell_type": "code", |
| 79 | + "execution_count": 5, |
| 80 | + "metadata": {}, |
| 81 | + "outputs": [ |
| 82 | + { |
| 83 | + "name": "stdout", |
| 84 | + "output_type": "stream", |
| 85 | + "text": [ |
| 86 | + "((0, 1, 2, 3), ('python', 'geek'))\n" |
| 87 | + ] |
| 88 | + } |
| 89 | + ], |
| 90 | + "source": [ |
| 91 | + "tuple1 = (0, 1, 2, 3) \n", |
| 92 | + "tuple2 = ('python', 'geek') \n", |
| 93 | + "tuple3 = (tuple1, tuple2) \n", |
| 94 | + "print(tuple3) " |
| 95 | + ] |
| 96 | + }, |
| 97 | + { |
| 98 | + "cell_type": "code", |
| 99 | + "execution_count": 6, |
| 100 | + "metadata": {}, |
| 101 | + "outputs": [ |
| 102 | + { |
| 103 | + "name": "stdout", |
| 104 | + "output_type": "stream", |
| 105 | + "text": [ |
| 106 | + "('python', 'python', 'python')\n" |
| 107 | + ] |
| 108 | + } |
| 109 | + ], |
| 110 | + "source": [ |
| 111 | + "tuple3 = ('python',)*3\n", |
| 112 | + "print(tuple3) " |
| 113 | + ] |
| 114 | + }, |
| 115 | + { |
| 116 | + "cell_type": "code", |
| 117 | + "execution_count": 8, |
| 118 | + "metadata": {}, |
| 119 | + "outputs": [ |
| 120 | + { |
| 121 | + "name": "stdout", |
| 122 | + "output_type": "stream", |
| 123 | + "text": [ |
| 124 | + "(1, 2, 3)\n", |
| 125 | + "(3, 2, 1, 0)\n", |
| 126 | + "(2, 3)\n" |
| 127 | + ] |
| 128 | + } |
| 129 | + ], |
| 130 | + "source": [ |
| 131 | + "tuple1 = (0 ,1, 2, 3) \n", |
| 132 | + "print(tuple1[1:]) \n", |
| 133 | + "print(tuple1[::-1]) \n", |
| 134 | + "print(tuple1[2:4]) " |
| 135 | + ] |
| 136 | + }, |
| 137 | + { |
| 138 | + "cell_type": "code", |
| 139 | + "execution_count": 9, |
| 140 | + "metadata": {}, |
| 141 | + "outputs": [ |
| 142 | + { |
| 143 | + "ename": "NameError", |
| 144 | + "evalue": "name 'tuple3' is not defined", |
| 145 | + "output_type": "error", |
| 146 | + "traceback": [ |
| 147 | + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", |
| 148 | + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", |
| 149 | + "\u001b[0;32m<ipython-input-9-b8c8cba15896>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mtuple3\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m(\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mdel\u001b[0m \u001b[0mtuple3\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtuple3\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", |
| 150 | + "\u001b[0;31mNameError\u001b[0m: name 'tuple3' is not defined" |
| 151 | + ] |
| 152 | + } |
| 153 | + ], |
| 154 | + "source": [ |
| 155 | + "tuple3 = (0, 1) \n", |
| 156 | + "del tuple3 \n", |
| 157 | + "print(tuple3) " |
| 158 | + ] |
| 159 | + }, |
21 | 160 | {
|
22 | 161 | "cell_type": "code",
|
23 | 162 | "execution_count": null,
|
|
0 commit comments