diff --git a/brisk_python.Rmd b/brisk_python.Rmd index 6851e55c..0b88e091 100644 --- a/brisk_python.Rmd +++ b/brisk_python.Rmd @@ -72,6 +72,13 @@ a + b a * b ``` +By default, jupyter notebook cells will only print the results of the last line of code when it is not assigned to a variable. To print the results of previous lines of codes in the cell as well, the function print() can be used: + +```{python} +print(a + b) +a * b +``` + Dividing an int by an int also gives a float: ```{python} @@ -107,7 +114,6 @@ The `%` operator on numbers gives you the remainder of integer division 5.0 % 2.0 ``` -(true-and-false)= ## True and False @@ -186,7 +192,6 @@ different from MATLAB, which uses `~=`: a != 1 ``` -(comparison-operators)= ## Comparison operators @@ -269,7 +274,7 @@ print('not True:', not True) print('not False:', not False) ``` -In fact, the logical operators will first force their arguments to be True or False before they give their answer. So, in the case of `and` or `or`, they force force their left and right arguents to be `bool` values, before they calculate the answer. So, in fact, you can use things other than exact True and False on either side of the `and` or `or`, as long as applying `bool(value)` to the thing to the left and right will produce a True or False value. See {doc}`truthiness` for more detail. +In fact, the logical operators will first force their arguments to be True or False before they give their answer. So, in the case of `and` or `or`, they force their left and right arguents to be `bool` values, before they calculate the answer. So, in fact, you can use things other than exact True and False on either side of the `and` or `or`, as long as applying `bool(value)` to the thing to the left and right will produce a True or False value. See {doc}`truthiness` for more detail. ## “If” statements, blocks and indention @@ -689,7 +694,6 @@ you a reversed copy of the list: my_list[::-1] ``` -(tuples)= ## Tuples @@ -869,7 +873,7 @@ characters removed from the beginning and end of the string: ```{python} # A string with a newline character at the end my_string = ' a string\n' -my_string +print(my_string) my_string.strip() ``` @@ -1064,7 +1068,7 @@ software = {} ``` Here we insert a new key / value mapping into the dictionary. The key is a -string — `'Python'` — and the corresponding value is an integer 50: +string — `'Python'` — and the corresponding value is an integer 100: ```{python} software['Python'] = 100 diff --git a/choosing_editor.md b/choosing_editor.md index 6ab8a06e..baf5e1fc 100644 --- a/choosing_editor.md +++ b/choosing_editor.md @@ -76,6 +76,7 @@ to PyCharm users). * [Sublime text](https://www.sublimetext.com) * [Emacs](https://emacs.org) * [Spyder](https://www.spyder-ide.org) +* [GitHub Codespaces](https://github.com/features/codespaces) ## Some version of Visual Studio Code diff --git a/the_software.md b/the_software.md index 2ad88e30..f4f616bb 100644 --- a/the_software.md +++ b/the_software.md @@ -40,7 +40,7 @@ post](http://asterisk.dynevor.org/python-matlab.html). ## The Jupyter Notebook -We will soon here more about the Jupyter Notebook. It is a particularly +We will soon hear more about the Jupyter Notebook. It is a particularly easy interface to run Python code, and display the results. The Notebook has two parts. The first is the web application, that you diff --git a/what_is_an_image.Rmd b/what_is_an_image.Rmd index 14eefa33..13b332c6 100644 --- a/what_is_an_image.Rmd +++ b/what_is_an_image.Rmd @@ -79,11 +79,16 @@ import os # module for interacting with the operating system If you want to explore modules or objects, type their name followed by a period, and press tab to see what functions or classes are available. -Try this now. Type ( followed by a period) then press tab, to see +Try this now. Type os (followed by a period) then press tab, to see what functions are in the `os` module. Continue typing so you have -`os.getcwd`, and then type `?` followed by Return. This shows you +`os.getcwd`, and then type `?` followed by SHIFT + Return. This shows you the help for the `os.getcwd` function. +```{python} +# Cell to follow instructions in the previous parragraph +os. +``` + For example, here we print out the Python's *working directory*. It is the directory that contains this notebook file. @@ -145,7 +150,7 @@ How do I find out what `type` of object is attached to this variable called How big is this file in terms of bytes? Can you find out from the `contents` variable? (Hint: you want to know the length of -`contents`). +`contents`; Hint 2: use function len() ). ```{python} # n_bytes = ?