Jupyter Notebooks
Contents
Jupyter Notebooks¶
Markdown
code cells
kernel
Cells¶
Cells are an independent ‘unit’. When you click into a cell, you can ‘run’ it by clicking Shift + Enter, or by pressing the play (Run) button above.
Cells come in different types for writing different things - mainly, text or code.
Markdown Cells¶
Cells, can be markdown (text), like this one.
A brief note about Markdown. It’s a way to specify all formatting within the text itself.
For example, italicized text can be specified with an underscore or single asterisks.
Bold text requires two underccores or two asterisks.
Clicker Question #2¶
What does three underscores around text accomplish?
A) bold
B) italicize
C) bold + italicize
D) normal text
E) I’m lost
you can write your markdown text here to determine the answer to the question
Markdown Headers¶
Headers are specified with a pound sign¶
The more pound signs, the smaller the header¶
But it’s still larger¶
than just plain text.
Lists are also possible:
item 1
item 2
item 3
numbered item
item 2
item 3
Clicker Question #3¶
What would happen if I specified a numbered list but put the same number before each list item?
A) the list would have the same number before each item
B) markdown would still format it with sequential numbers
C) markdown wouldn’t know it was a list
D) normal text with everything on a single line
E) I’m lost
test it out down here to see…
list item
list item
list item
* <- escape character
Code Cells¶
Whenever you’re writing code, you’ll want to be sure the cell is set to be a code cell
# Cell can also be code.
a = 1
b = 2
# Cells can also have output, that gets printed out below the cell.
c = a - b
print(c)
-1
# If you execute a cell with just a variable name in it, it will also get printed
c
-1
Running Cells¶
The numbers in the square brackets to the left of a cell show which cells have been run, and in what order.
An asterisk (*) means that the cell is currently running
You do not need to run cells in order! This is useful for flexibly testing and developing code.
Coding time¶
Write code that outputs the value ‘6’
## YOUR CODE HERE
a = 12
b = 1/2
print(b)
c = a * b
c
0.5
6.0
Clicker Question #5¶
Which of the following best describes you?
A) I completed the task.
B) I tried but wasn’t able to complete the task.
C) I am not sure where to start.
Accessing Documentation¶
# For example, execute this cell to see the documentation for the 'abs'
abs?
Autocomplete¶
# Move your cursor to the end of the line, press tab, and a drop menu will appear showing all possible completions
ra
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-6-c2c498cb5d74> in <module>()
1 # Move your cursor to the end of the line, press tab, and a drop menu will appear showing all possible completions
----> 2 ra
NameError: name 'ra' is not defined
# If there is only one option, tab-complete will auto-complete what you are typing
ran
Web Browser¶
If you click on the url in the browser, you will notice it says ‘localhost’. This means it is connected to something locally, on your computer.
That local connection is to the ‘kernel’.
Kernels¶
Your kernel also stores your namespace - all the variables and code that you have declared (executed).
It can be useful to clear and re-launch the kernel. You can do this from the ‘kernel’ drop down menu, at the top, optionally also clearing all ouputs. Note that this will erase any variables that are stored in memory.