|
16 | 16 | { |
17 | 17 | "cell_type": "markdown", |
18 | 18 | "metadata": { |
19 | | - "slideshow": { |
20 | | - "slide_type": "slide" |
21 | | - }, |
22 | 19 | "pycharm": { |
23 | 20 | "name": "#%% md\n" |
| 21 | + }, |
| 22 | + "slideshow": { |
| 23 | + "slide_type": "slide" |
24 | 24 | } |
25 | 25 | }, |
26 | 26 | "source": [ |
|
44 | 44 | }, |
45 | 45 | "source": [ |
46 | 46 | "## Resources\n", |
47 | | - "For more information, please consult the SFU Physics Department's [Computation Physics Website](https://www.sfu.ca/physics/computation.html) and the [Python Tutorial](https://docs.python.org/3/tutorial/)." |
| 47 | + "See the Jupyter [documentation](https://docs.jupyter.org/en/latest/) for more information about Jupyter notebooks." |
48 | 48 | ] |
49 | 49 | }, |
50 | 50 | { |
51 | 51 | "cell_type": "markdown", |
52 | 52 | "metadata": { |
53 | | - "slideshow": { |
54 | | - "slide_type": "slide" |
55 | | - }, |
56 | 53 | "pycharm": { |
57 | 54 | "name": "#%% md\n" |
| 55 | + }, |
| 56 | + "slideshow": { |
| 57 | + "slide_type": "slide" |
58 | 58 | } |
59 | 59 | }, |
60 | 60 | "source": [ |
|
65 | 65 | "cell_type": "code", |
66 | 66 | "execution_count": null, |
67 | 67 | "metadata": { |
68 | | - "slideshow": { |
69 | | - "slide_type": "-" |
70 | | - }, |
71 | 68 | "pycharm": { |
72 | 69 | "name": "#%%\n" |
| 70 | + }, |
| 71 | + "slideshow": { |
| 72 | + "slide_type": "-" |
73 | 73 | } |
74 | 74 | }, |
75 | 75 | "outputs": [], |
|
155 | 155 | "outputs": [], |
156 | 156 | "source": [ |
157 | 157 | "# In Python ** is used to calculate powers.\n", |
158 | | - "print(5 ** 2)\n", |
159 | | - "print(9 ** 0.5)" |
| 158 | + "print(5**2)\n", |
| 159 | + "print(9**0.5)" |
160 | 160 | ] |
161 | 161 | }, |
162 | 162 | { |
163 | 163 | "cell_type": "markdown", |
164 | 164 | "metadata": { |
165 | | - "slideshow": { |
166 | | - "slide_type": "slide" |
167 | | - }, |
168 | 165 | "pycharm": { |
169 | 166 | "name": "#%% md\n" |
| 167 | + }, |
| 168 | + "slideshow": { |
| 169 | + "slide_type": "slide" |
170 | 170 | } |
171 | 171 | }, |
172 | 172 | "source": [ |
|
178 | 178 | "cell_type": "code", |
179 | 179 | "execution_count": null, |
180 | 180 | "metadata": { |
181 | | - "slideshow": { |
182 | | - "slide_type": "-" |
183 | | - }, |
184 | 181 | "pycharm": { |
185 | 182 | "name": "#%%\n" |
| 183 | + }, |
| 184 | + "slideshow": { |
| 185 | + "slide_type": "-" |
186 | 186 | } |
187 | 187 | }, |
188 | 188 | "outputs": [], |
|
196 | 196 | { |
197 | 197 | "cell_type": "markdown", |
198 | 198 | "metadata": { |
199 | | - "slideshow": { |
200 | | - "slide_type": "subslide" |
201 | | - }, |
202 | 199 | "pycharm": { |
203 | 200 | "name": "#%% md\n" |
| 201 | + }, |
| 202 | + "slideshow": { |
| 203 | + "slide_type": "subslide" |
204 | 204 | } |
205 | 205 | }, |
206 | 206 | "source": [ |
207 | | - "In Python each variable has a type. You can return the varible's type by using the funtion type().\n" |
| 207 | + "In Python each variable has a type. You can return the variable's type by using the funtion [`type`](https://docs.python.org/3/library/functions.html#type).\n" |
208 | 208 | ] |
209 | 209 | }, |
210 | 210 | { |
|
290 | 290 | { |
291 | 291 | "cell_type": "markdown", |
292 | 292 | "metadata": { |
293 | | - "slideshow": { |
294 | | - "slide_type": "subslide" |
295 | | - }, |
296 | 293 | "pycharm": { |
297 | 294 | "name": "#%% md\n" |
| 295 | + }, |
| 296 | + "slideshow": { |
| 297 | + "slide_type": "subslide" |
298 | 298 | } |
299 | 299 | }, |
300 | 300 | "source": [ |
|
312 | 312 | }, |
313 | 313 | "outputs": [], |
314 | 314 | "source": [ |
315 | | - "# Use '' to define a string\n", |
316 | | - "a = 'Mercury'\n", |
317 | | - "\n", |
318 | 315 | "# Use \"\" to define a string\n", |
319 | | - "b = \"Venus\"\n", |
| 316 | + "a = \"Mercury\"\n", |
| 317 | + "\n", |
| 318 | + "# Use '' to define a string\n", |
| 319 | + "b = 'Venus'\n", |
320 | 320 | "\n", |
321 | 321 | "# If the string contains ' you can use \"\" to define it\n", |
322 | | - "c = \"Ceres isn't a planet \"\n", |
| 322 | + "c = \"Ceres isn't a planet\"\n", |
323 | 323 | "\n", |
324 | 324 | "print(a)\n", |
325 | 325 | "print(b)\n", |
326 | 326 | "print(c)\n", |
327 | | - "print('c is type: ', type(c))\n" |
| 327 | + "print(\"c is type: \", type(c))" |
328 | 328 | ] |
329 | 329 | }, |
330 | 330 | { |
|
339 | 339 | "source": [ |
340 | 340 | "# You can join (concatenate) strings using the '+' symbol\n", |
341 | 341 | "\n", |
342 | | - "a = 'Nep'\n", |
343 | | - "b = 'tune'\n", |
| 342 | + "a = \"Nep\"\n", |
| 343 | + "b = \"tune\"\n", |
344 | 344 | "\n", |
345 | 345 | "c = a + b\n", |
346 | 346 | "print(c)" |
|
349 | 349 | { |
350 | 350 | "cell_type": "markdown", |
351 | 351 | "metadata": { |
352 | | - "slideshow": { |
353 | | - "slide_type": "slide" |
354 | | - }, |
355 | 352 | "pycharm": { |
356 | 353 | "name": "#%% md\n" |
| 354 | + }, |
| 355 | + "slideshow": { |
| 356 | + "slide_type": "slide" |
357 | 357 | } |
358 | 358 | }, |
359 | 359 | "source": [ |
|
394 | 394 | "# A list may be composed of different variable types,\n", |
395 | 395 | "# including other lists.\n", |
396 | 396 | "\n", |
397 | | - "my_list = [1, 2, 'a', 5, [1, 4, 7]]\n", |
| 397 | + "my_list = [1, 2, \"a\", 5, [1, 4, 7]]\n", |
398 | 398 | "print(my_list)" |
399 | 399 | ] |
400 | 400 | }, |
|
411 | 411 | "# The '+' operation acts on lists by joining them.\n", |
412 | 412 | "\n", |
413 | 413 | "a = [1, 2, 4]\n", |
414 | | - "b = ['a', 'b', 'c']\n", |
| 414 | + "b = [\"a\", \"b\", \"c\"]\n", |
415 | 415 | "c = a + b\n", |
416 | 416 | "print(c)" |
417 | 417 | ] |
|
525 | 525 | "outputs": [], |
526 | 526 | "source": [ |
527 | 527 | "# We can select a range of indices by separating the start\n", |
528 | | - "# and stop index with a colon, a[start:stop]. This is called the slice operator. \n", |
| 528 | + "# and stop index with a colon, a[start:stop]. This is called the slice operator.\n", |
529 | 529 | "# This will return all elements beginning with the 'start' index and\n", |
530 | 530 | "# ending with the largest index that is below 'stop'.\n", |
531 | | - "# If you omit the first index (before the colon), the \n", |
532 | | - "# slice starts at the beginning of the string. If you omit the second \n", |
| 531 | + "# If you omit the first index (before the colon), the\n", |
| 532 | + "# slice starts at the beginning of the string. If you omit the second\n", |
533 | 533 | "# index, the slice goes to the end of the string.\n", |
534 | 534 | "print(a[0:3])" |
535 | 535 | ] |
|
544 | 544 | }, |
545 | 545 | "outputs": [], |
546 | 546 | "source": [ |
547 | | - "# If you omit the first index (before the colon), the \n", |
548 | | - "# slice starts at the beginning of the string. \n", |
| 547 | + "# If you omit the first index (before the colon), the\n", |
| 548 | + "# slice starts at the beginning of the string.\n", |
549 | 549 | "print(a[:3])" |
550 | 550 | ] |
551 | 551 | }, |
|
612 | 612 | "source": [ |
613 | 613 | "# Indexing also works with strings. The string is then considered as a list of characters.\n", |
614 | 614 | "\n", |
615 | | - "a = 'Kuiper belt'\n", |
| 615 | + "a = \"Kuiper belt\"\n", |
616 | 616 | "\n", |
617 | 617 | "# Print the first letter\n", |
618 | 618 | "print(a[0])\n", |
619 | 619 | "\n", |
620 | 620 | "# Print the third letter\n", |
621 | 621 | "print(a[2])\n", |
622 | 622 | "\n", |
623 | | - "# Print a section \n", |
| 623 | + "# Print a section\n", |
624 | 624 | "print(a[2:5])\n", |
625 | 625 | "print(a[7:])\n", |
626 | 626 | "print(a[:6])\n", |
|
651 | 651 | "\n", |
652 | 652 | "* [The Python Tutorial](https://docs.python.org/3/tutorial/).\n", |
653 | 653 | "\n", |
654 | | - "* [SciPy User Guide](https://docs.scipy.org/doc/scipy/reference/tutorial/index.html).\n", |
| 654 | + "* [SciPy User Guide](https://docs.scipy.org/doc/scipy/tutorial/index.html).\n", |
655 | 655 | "\n", |
656 | | - "* [NumPy User Guide](https://docs.scipy.org/doc/numpy/user/index.html#user).\n", |
| 656 | + "* [NumPy User Guide](https://numpy.org/doc/stable/user/index.html#user).\n", |
657 | 657 | "\n", |
658 | 658 | "* Guido van Rossum, Barry Warsaw, and Nick Coghlan, [PEP 8 -- Style Guide for Python Code](https://www.python.org/dev/peps/pep-0008). The standard style guide for Python code.\n" |
659 | 659 | ] |
|
667 | 667 | }, |
668 | 668 | "source": [ |
669 | 669 | "##### About this notebook\n", |
670 | | - "© J. Steven Dodge, 2019. The notebook text is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. See more at [Creative Commons](https://creativecommons.org/licenses/by-nc-nd/4.0/). The notebook code is open source under the [MIT License](https://opensource.org/licenses/MIT)." |
| 670 | + "© J. Steven Dodge, 2019. The notebook text is licensed under CC BY 4.0. See more at [Creative Commons](https://creativecommons.org/licenses/by/4.0/). The notebook code is open source under the [MIT License](https://opensource.org/licenses/MIT)." |
671 | 671 | ] |
672 | 672 | } |
673 | 673 | ], |
674 | 674 | "metadata": { |
675 | 675 | "kernelspec": { |
676 | | - "display_name": "Python 3", |
| 676 | + "display_name": "Python 3 (ipykernel)", |
677 | 677 | "language": "python", |
678 | 678 | "name": "python3" |
679 | 679 | }, |
|
687 | 687 | "name": "python", |
688 | 688 | "nbconvert_exporter": "python", |
689 | 689 | "pygments_lexer": "ipython3", |
690 | | - "version": "3.9.5" |
| 690 | + "version": "3.11.3" |
691 | 691 | } |
692 | 692 | }, |
693 | 693 | "nbformat": 4, |
|
0 commit comments