Skip to content

Commit 990ea55

Browse files
committed
Adding in the first lesson
1 parent 4fbb4f0 commit 990ea55

1 file changed

Lines changed: 158 additions & 0 deletions

File tree

‎01_jupyter_howto.ipynb‎

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# What is Jupyter and how do you use it?\n",
8+
"\n",
9+
"[Project Jupyter](http://jupyter.org) exists to develop software and standards for interactive computing. Jupyter, which you are using now, provides an interactive notebook which runs on a cloud-server, and with which you interact using a web browser.\n",
10+
"\n",
11+
"As installed, Jupyter provides two things:\n",
12+
"\n",
13+
"* An interactive Python notebook, which you are using now (this is an interactive notebook!)\n",
14+
"* An interactive bash terminal (we will use this later)\n",
15+
"\n",
16+
"What is an interactive Python notebook? It is a notebook that mixes documentation (like this!) with Python code (like below), with the output of that code.\n",
17+
"\n",
18+
"For example, below is the Python code to print \"Hello World\". Click on the below code and then press \"SHIFT+Return\". You should see that the code is run, and below \"Hello World\" will be printed."
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": 3,
24+
"metadata": {},
25+
"outputs": [
26+
{
27+
"name": "stdout",
28+
"output_type": "stream",
29+
"text": [
30+
"Hello World\n"
31+
]
32+
}
33+
],
34+
"source": [
35+
"print(\"Hello World\")"
36+
]
37+
},
38+
{
39+
"cell_type": "markdown",
40+
"metadata": {},
41+
"source": [
42+
"The above code is interactive because it runs when you pressed \"SHIFT+Return\". It is also interactive because you can change it. For example, click again on the code and change \"Hello World\" to \"Hello Jupyter\". Press \"SHIFT+Return\" again and you should see \"Hello Jupyter\" printed.\n",
43+
"\n",
44+
"A code cell can have as much or little Python in it as you want. The below cell defines a function and then runs it in a loop. What do you think will be printed out when you select it and press \"SHIFT+Return\"? Have a go. Are you right?"
45+
]
46+
},
47+
{
48+
"cell_type": "code",
49+
"execution_count": 5,
50+
"metadata": {},
51+
"outputs": [
52+
{
53+
"name": "stdout",
54+
"output_type": "stream",
55+
"text": [
56+
"10...\n",
57+
"9...\n",
58+
"8...\n",
59+
"7...\n",
60+
"6...\n",
61+
"5...\n",
62+
"4...\n",
63+
"3...\n",
64+
"2...\n",
65+
"1...\n",
66+
"Lift off!\n"
67+
]
68+
}
69+
],
70+
"source": [
71+
"def countDown(start):\n",
72+
" for i in range(start, 0, -1):\n",
73+
" print(\"%d...\" % i)\n",
74+
" print(\"Lift off!\")\n",
75+
" \n",
76+
"countDown(10)"
77+
]
78+
},
79+
{
80+
"cell_type": "markdown",
81+
"metadata": {},
82+
"source": [
83+
"Each cell can use the variables and functions defined in previous cells. For example, the next cell sets the value of the variable `x` to 5, while the following cell then uses that to call the `countDown` function."
84+
]
85+
},
86+
{
87+
"cell_type": "code",
88+
"execution_count": 10,
89+
"metadata": {},
90+
"outputs": [],
91+
"source": [
92+
"x = 21"
93+
]
94+
},
95+
{
96+
"cell_type": "code",
97+
"execution_count": 9,
98+
"metadata": {},
99+
"outputs": [
100+
{
101+
"name": "stdout",
102+
"output_type": "stream",
103+
"text": [
104+
"7...\n",
105+
"6...\n",
106+
"5...\n",
107+
"4...\n",
108+
"3...\n",
109+
"2...\n",
110+
"1...\n",
111+
"Lift off!\n"
112+
]
113+
}
114+
],
115+
"source": [
116+
"countDown(x)"
117+
]
118+
},
119+
{
120+
"cell_type": "markdown",
121+
"metadata": {},
122+
"source": [
123+
"You can go back up and edit the value of `x`. For example, set `x` to 7 and press SHIFT+Return. This has changed `x`. However, it doesn't re-run any code that depends on `x`. That is for you to do. You need to click on the next cell `countDown(x)` and press SHIFT+Return again. You should then see that the code is run and updated.\n",
124+
"\n",
125+
"Because you can change any cell at any time, a notebook can get into a confused state. If we change `x` again to `21`, then the cell `countDown(x)`, is now out of date, as it depends on the old value of `x`. So, how can we know what state each cell is in?\n",
126+
"\n"
127+
]
128+
},
129+
{
130+
"cell_type": "code",
131+
"execution_count": null,
132+
"metadata": {},
133+
"outputs": [],
134+
"source": []
135+
}
136+
],
137+
"metadata": {
138+
"kernelspec": {
139+
"display_name": "Python 3",
140+
"language": "python",
141+
"name": "python3"
142+
},
143+
"language_info": {
144+
"codemirror_mode": {
145+
"name": "ipython",
146+
"version": 3
147+
},
148+
"file_extension": ".py",
149+
"mimetype": "text/x-python",
150+
"name": "python",
151+
"nbconvert_exporter": "python",
152+
"pygments_lexer": "ipython3",
153+
"version": "3.5.2"
154+
}
155+
},
156+
"nbformat": 4,
157+
"nbformat_minor": 2
158+
}

0 commit comments

Comments
 (0)