01 Notebook Fundamentals (Python)
. The notebook language is always shown in parenthesis following the notebook title.1 + 1
has not been evaluated. To run the code cell, select the cell by placing your cursor within the cell text area and do any of the following:Shift
+ Enter
(to run the current cell and advance to the next cell)Ctrl
+ Enter
(to run the current cell, but keep the current cell selected)%
.%md
.%python
- Allows you to execute Python code in the cell.%r
- Allows you to execute R code in the cell.%scala
- Allows you to execute Scala code in the cell.%sql
- Allows you to execute SQL statements in the cell.sh
- Allows you to execute Bash Shell commmands and code in the cell.fs
- Allows you to execute Databricks Filesystem commands in the cell.md
- Allows you to render Markdown syntax as formatted content in the cell.run
- Allows you to run another notebook from a cell in the current notebook.ENTER
) and notice how the cell changes to an editable code cell. Observe that the first line starts with %md
. This magic instructs the notebook not to run the cell contents as python, but instead to render the contents from the markdown syntax.Esc
key.Run All
in the notebook toolbar to run all cells starting from the first.up
or down
arrows. If your cursor is within a code cell, keep pressing up or down until your reach the top or bottom edge of the cell respectively and the focus will automatically jump to the next cell.X
to cut it. Use the up
or down
arrow keys to find the cell around which it should be pasted. Press V
to paste the cell below the selected cell or press SHIFT
+ V
to paste the cell above the selected cell.caret
and then selecting either Move Up
or Move Down
or the Cut Cell
and Paste Cell
options.y = x + 1
and y
. And re-run that cell. Did the value of y
meet your expectation?y
should now be 101
. This is because it is not the actual order of the cells that determines the value, but the order in which they are run and how that affects the underlying state itself. To understand this, realize that when the code x = 100
was run, this changed the value of x
, and then when you re-ran the cell containing y = x + 1
this evaluation used the current value of x which is 100. This resulted in y
having a value of 101
and not 11
.
No comments:
Post a Comment