Copyright 2019 StarkWare Industries Ltd.
Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.starkware.co/open-source-license/
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
A Python notebook is "...an interactive computational environment, in which you can combine code execution, rich text, mathematics, plots and rich media".
The left pane lists the current directory in the backend. Files with .ipynb
extension are notebook documents, like this one. But you can use it to view other text files. Try it - double click channel.py
. Then come back to this document.
Each notebook document is comprised of cells. This tutorial has two types:
You can use Ctrl+Enter to run a cell, a markdown cell will get rendered nicely, a code cell will just run the code.
Everything you read up to this point is part of a markdown cell.
# This is a code cell, note the square brackets on its left - they are important.
# Run this cell by clicking into it and pressing Ctrl+Enter.
for i in range(3):
print(i)
# This is a different cell, but while you are in the same document - global variables persist.
# The part of the notebook maintaining this state is called the kernel, and can be restarted (for the entire document) using the dropdown menus.
# Run this cell too to see (Ctrl+Enter).
print(f'See how i\'s value is still {i}.')
Ctrl+Enter runs the selected cell. Shift+Enter runs it and selects the next cell.
These brackets are in one of these three states:
*
if they are currently running or queued to run (i.e. you ran it while another cell didn't finish running yet).Try running the next cell, don't wait for it to finish, and run the first code cell again, to see this in action.
from time import sleep
print('Going to sleep.')
sleep(5)
print('Hello world.')
You can call a function without arguments, followed by a question mark, to get its documentation. Run the next cell to see what it looks like.
print?
Open Stark101-part1.ipynb
to start the tutorial.