|
157 | 157 | "print(tuple3) "
|
158 | 158 | ]
|
159 | 159 | },
|
| 160 | + { |
| 161 | + "cell_type": "code", |
| 162 | + "execution_count": 10, |
| 163 | + "metadata": {}, |
| 164 | + "outputs": [ |
| 165 | + { |
| 166 | + "name": "stdout", |
| 167 | + "output_type": "stream", |
| 168 | + "text": [ |
| 169 | + "2\n" |
| 170 | + ] |
| 171 | + } |
| 172 | + ], |
| 173 | + "source": [ |
| 174 | + "tuple2 = ('python', 'geek') \n", |
| 175 | + "print(len(tuple2)) " |
| 176 | + ] |
| 177 | + }, |
| 178 | + { |
| 179 | + "cell_type": "code", |
| 180 | + "execution_count": 11, |
| 181 | + "metadata": {}, |
| 182 | + "outputs": [ |
| 183 | + { |
| 184 | + "name": "stdout", |
| 185 | + "output_type": "stream", |
| 186 | + "text": [ |
| 187 | + "(0, 1, 2)\n", |
| 188 | + "('p', 'y', 't', 'h', 'o', 'n')\n" |
| 189 | + ] |
| 190 | + } |
| 191 | + ], |
| 192 | + "source": [ |
| 193 | + "list1 = [0, 1, 2] \n", |
| 194 | + "print(tuple(list1)) \n", |
| 195 | + "print(tuple('python'))" |
| 196 | + ] |
| 197 | + }, |
| 198 | + { |
| 199 | + "cell_type": "code", |
| 200 | + "execution_count": 14, |
| 201 | + "metadata": {}, |
| 202 | + "outputs": [ |
| 203 | + { |
| 204 | + "name": "stdout", |
| 205 | + "output_type": "stream", |
| 206 | + "text": [ |
| 207 | + "(('python',),)\n", |
| 208 | + "((('python',),),)\n", |
| 209 | + "(((('python',),),),)\n", |
| 210 | + "((((('python',),),),),)\n", |
| 211 | + "(((((('python',),),),),),)\n" |
| 212 | + ] |
| 213 | + } |
| 214 | + ], |
| 215 | + "source": [ |
| 216 | + "tup = ('python',) \n", |
| 217 | + "n = 5 \n", |
| 218 | + "for i in range(int(n)): \n", |
| 219 | + " tup = (tup,) \n", |
| 220 | + " print(tup) " |
| 221 | + ] |
| 222 | + }, |
| 223 | + { |
| 224 | + "cell_type": "code", |
| 225 | + "execution_count": 15, |
| 226 | + "metadata": {}, |
| 227 | + "outputs": [ |
| 228 | + { |
| 229 | + "ename": "NameError", |
| 230 | + "evalue": "name 'cmp' is not defined", |
| 231 | + "output_type": "error", |
| 232 | + "traceback": [ |
| 233 | + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", |
| 234 | + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", |
| 235 | + "\u001b[0;32m<ipython-input-15-a9bcf8d03232>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mtuple2\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;34m'coder'\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 3\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0;32mif\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mcmp\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtuple1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtuple2\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;31m# cmp() returns 0 if matched, 1 when not tuple1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", |
| 236 | + "\u001b[0;31mNameError\u001b[0m: name 'cmp' is not defined" |
| 237 | + ] |
| 238 | + } |
| 239 | + ], |
| 240 | + "source": [ |
| 241 | + "tuple1 = ('python', 'geek') \n", |
| 242 | + "tuple2 = ('coder', 1) \n", |
| 243 | + " \n", |
| 244 | + "if (cmp(tuple1, tuple2) != 0): \n", |
| 245 | + " \n", |
| 246 | + " # cmp() returns 0 if matched, 1 when not tuple1 \n", |
| 247 | + " # is longer and -1 when tuple1 is shoter \n", |
| 248 | + " print('Not the same') \n", |
| 249 | + "else: \n", |
| 250 | + " print('Same') \n", |
| 251 | + "print ('Maximum element in tuples 1,2: ' + \n", |
| 252 | + " str(max(tuple1)) + ',' + \n", |
| 253 | + " str(max(tuple2))) \n", |
| 254 | + "print ('Minimum element in tuples 1,2: ' + \n", |
| 255 | + " str(min(tuple1)) + ',' + str(min(tuple2))) " |
| 256 | + ] |
| 257 | + }, |
160 | 258 | {
|
161 | 259 | "cell_type": "code",
|
162 | 260 | "execution_count": null,
|
|
0 commit comments