Lecture 1

Hello, this is a notebook. It consists of cells. Each cell is a code or markdown cell.

Double-click (or press enter) to edit a cell. Press Shift+Enter to run a cell.

In [1]:
# this is a code cell
# press shift+enter to run it when it is selected
16*16
Out[1]:
256
In [2]:
# By the way, lines that start with sharp key are comments
# comments are ignored by python
# 16*16

Markdown format

Markdown is a way to format text easily: Choose in menu above: Cell -> Cell Type to toggle markdown or code (shortcuts: M and Y)

Double click this cell to see the code for it.

Title

Subtitle

Subsubtitle

Subsubsubtitle

Subsubsubsubsubtitle
Subsubsubsubsubsubtitle
# It gave up at this point

The last word of this sentence is emphasized. The last word of this sentence is booooold.



good old html code also works

Math can also be included using latex, e.g. $e^{i\pi} = -1$ $$\frac{d}{dx} x^3 = 3{x^2}$$

Here's a quick markdown tutorial: link



Code blocks, expressions

Press Shift+Enter to run the code

It's the best calculator

In [3]:
3*5
Out[3]:
15
In [4]:
3/4
Out[4]:
0.75
In [5]:
27 % 11
Out[5]:
5
In [6]:
27 // 11
Out[6]:
2
In [7]:
2**10
Out[7]:
1024

Priority

In [8]:
4 * 2 - 5 * 2
Out[8]:
-2
In [9]:
4 * (2 - 5) * 2
Out[9]:
-24
In [10]:
3 / 2 * 5
Out[10]:
7.5
In [11]:
3 / (2 * 5)
Out[11]:
0.3

Multiplication and addition have priority. Between * and / it's left to right.

In [12]:
#Weird stuff:
5*"hello."
Out[12]:
'hello.hello.hello.hello.hello.'


Calling functions:

In [13]:
# single variable
abs(-5.1)
Out[13]:
5.1
In [14]:
# multi-variable
max(3,4)
Out[14]:
4
In [15]:
cos(0)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-15-eddb8697e1ef> in <module>()
----> 1 cos(0)

NameError: name 'cos' is not defined

whatt?! it doesn't know cos?!?!!
it's because cos is in an extra module we need to import

In [16]:
import math
math.cos(0)
Out[16]:
1.0
In [17]:
# no need to import again
math.cos(math.pi)
Out[17]:
-1.0



Strings

In [18]:
"This is a string"
Out[18]:
'This is a string'
In [19]:
# adding strings is string concatenation
"hel" + "lo"
Out[19]:
'hello'