|
32 | 32 | "- Python 2 is retired use only Python 3\n" |
33 | 33 | ] |
34 | 34 | }, |
35 | | - { |
36 | | - "cell_type": "markdown", |
37 | | - "metadata": {}, |
38 | | - "source": [ |
39 | | - "## Python distributions\n", |
40 | | - "\n", |
41 | | - " Python packages are available with all linux distributions but you can get standalone bundles:\n", |
42 | | - "\n", |
43 | | - "- [Anaconda](https://www.continuum.io/downloads)\n", |
44 | | - "- [Enthought Tools Suite](https://docs.enthought.com/ets/)\n", |
45 | | - "- [Astropy](http://www.astropy.org)\n", |
46 | | - "- [SAGEMATH](http://sagemath.org/)\n", |
47 | | - "- [Pyzo](http://www.pyzo.org)\n" |
48 | | - ] |
49 | | - }, |
50 | 35 | { |
51 | 36 | "cell_type": "markdown", |
52 | 37 | "metadata": {}, |
|
143 | 128 | }, |
144 | 129 | { |
145 | 130 | "cell_type": "code", |
146 | | - "execution_count": null, |
147 | | - "metadata": {}, |
148 | | - "outputs": [], |
| 131 | + "execution_count": 1, |
| 132 | + "metadata": {}, |
| 133 | + "outputs": [ |
| 134 | + { |
| 135 | + "name": "stdout", |
| 136 | + "output_type": "stream", |
| 137 | + "text": [ |
| 138 | + "<class 'str'> Hello World!\n" |
| 139 | + ] |
| 140 | + } |
| 141 | + ], |
149 | 142 | "source": [ |
150 | 143 | "s = \"Hello World!\"\n", |
151 | 144 | "print(type(s),s)" |
152 | 145 | ] |
153 | 146 | }, |
154 | 147 | { |
155 | 148 | "cell_type": "code", |
156 | | - "execution_count": null, |
157 | | - "metadata": {}, |
158 | | - "outputs": [], |
| 149 | + "execution_count": 2, |
| 150 | + "metadata": {}, |
| 151 | + "outputs": [ |
| 152 | + { |
| 153 | + "name": "stdout", |
| 154 | + "output_type": "stream", |
| 155 | + "text": [ |
| 156 | + "<class 'int'> 6625\n" |
| 157 | + ] |
| 158 | + } |
| 159 | + ], |
159 | 160 | "source": [ |
160 | 161 | "a = 6625\n", |
161 | 162 | "print(type(a),a)" |
162 | 163 | ] |
163 | 164 | }, |
164 | 165 | { |
165 | 166 | "cell_type": "code", |
166 | | - "execution_count": null, |
| 167 | + "execution_count": 3, |
167 | 168 | "metadata": {}, |
168 | 169 | "outputs": [], |
169 | 170 | "source": [ |
|
179 | 180 | }, |
180 | 181 | { |
181 | 182 | "cell_type": "code", |
182 | | - "execution_count": null, |
183 | | - "metadata": {}, |
184 | | - "outputs": [], |
| 183 | + "execution_count": 4, |
| 184 | + "metadata": {}, |
| 185 | + "outputs": [ |
| 186 | + { |
| 187 | + "name": "stdout", |
| 188 | + "output_type": "stream", |
| 189 | + "text": [ |
| 190 | + "Writing hello.py\n" |
| 191 | + ] |
| 192 | + } |
| 193 | + ], |
185 | 194 | "source": [ |
186 | 195 | "%%file hello.py\n", |
187 | 196 | "\n", |
|
221 | 230 | }, |
222 | 231 | { |
223 | 232 | "cell_type": "code", |
224 | | - "execution_count": null, |
225 | | - "metadata": {}, |
226 | | - "outputs": [], |
| 233 | + "execution_count": 5, |
| 234 | + "metadata": {}, |
| 235 | + "outputs": [ |
| 236 | + { |
| 237 | + "name": "stdout", |
| 238 | + "output_type": "stream", |
| 239 | + "text": [ |
| 240 | + "<class 'str'> Hello World!\n", |
| 241 | + "<class 'int'> 6625\n" |
| 242 | + ] |
| 243 | + } |
| 244 | + ], |
227 | 245 | "source": [ |
228 | 246 | "%run hello.py" |
229 | 247 | ] |
|
239 | 257 | }, |
240 | 258 | { |
241 | 259 | "cell_type": "code", |
242 | | - "execution_count": null, |
243 | | - "metadata": {}, |
244 | | - "outputs": [], |
| 260 | + "execution_count": 6, |
| 261 | + "metadata": {}, |
| 262 | + "outputs": [ |
| 263 | + { |
| 264 | + "name": "stdout", |
| 265 | + "output_type": "stream", |
| 266 | + "text": [ |
| 267 | + "<class 'int'>\n", |
| 268 | + "<class 'float'>\n", |
| 269 | + "<class 'bool'>\n", |
| 270 | + "<class 'NoneType'>\n", |
| 271 | + "<class 'complex'>\n", |
| 272 | + "<class 'type'>\n" |
| 273 | + ] |
| 274 | + } |
| 275 | + ], |
245 | 276 | "source": [ |
246 | 277 | "s = int(2010); print(type(s))\n", |
247 | 278 | "s = 3.14; print(type(s))\n", |
|
260 | 291 | }, |
261 | 292 | { |
262 | 293 | "cell_type": "code", |
263 | | - "execution_count": null, |
264 | | - "metadata": {}, |
265 | | - "outputs": [], |
| 294 | + "execution_count": 7, |
| 295 | + "metadata": {}, |
| 296 | + "outputs": [ |
| 297 | + { |
| 298 | + "name": "stdout", |
| 299 | + "output_type": "stream", |
| 300 | + "text": [ |
| 301 | + "47 True\n" |
| 302 | + ] |
| 303 | + } |
| 304 | + ], |
266 | 305 | "source": [ |
267 | 306 | "x = 45 # This is a comment!\n", |
268 | 307 | "x += 2 # equivalent to x = x + 2\n", |
|
271 | 310 | }, |
272 | 311 | { |
273 | 312 | "cell_type": "code", |
274 | | - "execution_count": null, |
275 | | - "metadata": {}, |
276 | | - "outputs": [], |
| 313 | + "execution_count": 8, |
| 314 | + "metadata": {}, |
| 315 | + "outputs": [ |
| 316 | + { |
| 317 | + "name": "stdout", |
| 318 | + "output_type": "stream", |
| 319 | + "text": [ |
| 320 | + "x+y= 49.5 <class 'float'>\n" |
| 321 | + ] |
| 322 | + } |
| 323 | + ], |
277 | 324 | "source": [ |
278 | 325 | "y = 2.5\n", |
279 | 326 | "print(\"x+y=\",x+y, type(x+y)) # Add float to integer, result will be a float" |
280 | 327 | ] |
281 | 328 | }, |
282 | 329 | { |
283 | 330 | "cell_type": "code", |
284 | | - "execution_count": null, |
285 | | - "metadata": {}, |
286 | | - "outputs": [], |
| 331 | + "execution_count": 9, |
| 332 | + "metadata": {}, |
| 333 | + "outputs": [ |
| 334 | + { |
| 335 | + "name": "stdout", |
| 336 | + "output_type": "stream", |
| 337 | + "text": [ |
| 338 | + "188.0\n", |
| 339 | + "156\n" |
| 340 | + ] |
| 341 | + } |
| 342 | + ], |
287 | 343 | "source": [ |
288 | 344 | "print(x*10/y) # true division returns a float\n", |
289 | 345 | "print(x*10//3) # floor division discards the fractional part" |
290 | 346 | ] |
291 | 347 | }, |
292 | 348 | { |
293 | 349 | "cell_type": "code", |
294 | | - "execution_count": null, |
295 | | - "metadata": {}, |
296 | | - "outputs": [], |
| 350 | + "execution_count": 10, |
| 351 | + "metadata": {}, |
| 352 | + "outputs": [ |
| 353 | + { |
| 354 | + "name": "stdout", |
| 355 | + "output_type": "stream", |
| 356 | + "text": [ |
| 357 | + "7\n" |
| 358 | + ] |
| 359 | + } |
| 360 | + ], |
297 | 361 | "source": [ |
298 | 362 | "print( x % 8) # the % operator returns the remainder of the division" |
299 | 363 | ] |
300 | 364 | }, |
301 | 365 | { |
302 | 366 | "cell_type": "code", |
303 | | - "execution_count": null, |
304 | | - "metadata": {}, |
305 | | - "outputs": [], |
| 367 | + "execution_count": 11, |
| 368 | + "metadata": {}, |
| 369 | + "outputs": [ |
| 370 | + { |
| 371 | + "name": "stdout", |
| 372 | + "output_type": "stream", |
| 373 | + "text": [ |
| 374 | + " x = 00047 \n" |
| 375 | + ] |
| 376 | + } |
| 377 | + ], |
306 | 378 | "source": [ |
307 | 379 | "print( f\" x = {x:05d} \") # You can use C format rules to improve print output" |
308 | 380 | ] |
|
320 | 392 | }, |
321 | 393 | { |
322 | 394 | "cell_type": "code", |
323 | | - "execution_count": null, |
324 | | - "metadata": {}, |
325 | | - "outputs": [], |
| 395 | + "execution_count": 12, |
| 396 | + "metadata": {}, |
| 397 | + "outputs": [ |
| 398 | + { |
| 399 | + "name": "stdout", |
| 400 | + "output_type": "stream", |
| 401 | + "text": [ |
| 402 | + "1 1 1\n" |
| 403 | + ] |
| 404 | + } |
| 405 | + ], |
326 | 406 | "source": [ |
327 | 407 | "a = b = c = 1\n", |
328 | 408 | "print(a, b, c) " |
329 | 409 | ] |
330 | 410 | }, |
331 | 411 | { |
332 | 412 | "cell_type": "code", |
333 | | - "execution_count": null, |
334 | | - "metadata": {}, |
335 | | - "outputs": [], |
| 413 | + "execution_count": 13, |
| 414 | + "metadata": {}, |
| 415 | + "outputs": [ |
| 416 | + { |
| 417 | + "name": "stdout", |
| 418 | + "output_type": "stream", |
| 419 | + "text": [ |
| 420 | + "1 2 3\n" |
| 421 | + ] |
| 422 | + } |
| 423 | + ], |
336 | 424 | "source": [ |
337 | 425 | "a, b, c = 1, 2, 3\n", |
338 | 426 | "print (a, b, c)" |
339 | 427 | ] |
340 | 428 | }, |
341 | 429 | { |
342 | 430 | "cell_type": "code", |
343 | | - "execution_count": null, |
344 | | - "metadata": {}, |
345 | | - "outputs": [], |
| 431 | + "execution_count": 14, |
| 432 | + "metadata": {}, |
| 433 | + "outputs": [ |
| 434 | + { |
| 435 | + "name": "stdout", |
| 436 | + "output_type": "stream", |
| 437 | + "text": [ |
| 438 | + "3 2 1\n" |
| 439 | + ] |
| 440 | + } |
| 441 | + ], |
346 | 442 | "source": [ |
347 | 443 | "a, c = c, a # Nice way to permute values\n", |
348 | 444 | "print (a, b, c) " |
349 | 445 | ] |
350 | 446 | }, |
351 | 447 | { |
352 | 448 | "cell_type": "code", |
353 | | - "execution_count": null, |
354 | | - "metadata": {}, |
355 | | - "outputs": [], |
| 449 | + "execution_count": 15, |
| 450 | + "metadata": {}, |
| 451 | + "outputs": [ |
| 452 | + { |
| 453 | + "data": { |
| 454 | + "text/plain": [ |
| 455 | + "(False, True)" |
| 456 | + ] |
| 457 | + }, |
| 458 | + "execution_count": 15, |
| 459 | + "metadata": {}, |
| 460 | + "output_type": "execute_result" |
| 461 | + } |
| 462 | + ], |
356 | 463 | "source": [ |
357 | 464 | "a < b < c, a > b > c" |
358 | 465 | ] |
|
377 | 484 | ], |
378 | 485 | "metadata": { |
379 | 486 | "kernelspec": { |
380 | | - "display_name": "Python 3", |
| 487 | + "display_name": "Python 3 (ipykernel)", |
381 | 488 | "language": "python", |
382 | 489 | "name": "python3" |
383 | 490 | }, |
|
391 | 498 | "name": "python", |
392 | 499 | "nbconvert_exporter": "python", |
393 | 500 | "pygments_lexer": "ipython3", |
394 | | - "version": "3.8.5" |
| 501 | + "version": "3.10.14" |
395 | 502 | } |
396 | 503 | }, |
397 | 504 | "nbformat": 4, |
|
0 commit comments