Monday, August 25th, 2025¶
Getting started with Jupyter notebook¶
- We can execute a cell using
SHIFT
+ENTER
. - We can add a new cell using the plus symbol in the top-left corner. Alternatively, you can select a cell and hit
A
to add a cell above, orB
to add a cell below. - We can delete a cell by selecting hit, then hitting
D
,D
.
2 + 7
9
100 + 7
107
Arithmetic operations¶
Addition:
400 + 3
403
Subtraction:
300 - 5
295
Multiplication:
50 * 3
150
Division:
10 / 2
5.0
Exponentiation:
2^5
7
To perform exponentiation, use **
or the pow
function instead of ^
:
2**5
32
pow(2,5)
32
Using the standard division /
will return what is called a float.
5 / 2
2.5
6/3
2.0
5 / 3
1.6666666666666667
Integers vs floats¶
- integers = numbers without any decimal point
- floats = numbers with a decimal point
- operations on integers are exact
- operations on floats are approximate
- integers can be arbitrarily large, but floats are represented only within a finite range.
2.0 ** 100
1.2676506002282294e+30
2**100
1267650600228229401496703205376
2.0**1200
--------------------------------------------------------------------------- OverflowError Traceback (most recent call last) Cell In[23], line 1 ----> 1 2.0**1200 OverflowError: (34, 'Result too large')
2**1200
17218479456385750618067377696052635483579924745448689921733236816400740691241745619397484537236046173286370919031961587788584927290816661024991609882728717344659503471655990880884679896520055123906467064419056526231345685268240569209892573766037966584735183775739433978714578587782701380797240772477647874555986712746271362892227516205318914435913511141036261376
Markdown¶
Markdown is a markup language used for creating formatted text. In Jupyter, we create Markdown cells for this text.
This cell will throw an error.
Cell In[27], line 1 This cell will throw an error. ^ SyntaxError: invalid syntax
This cell will not throw an error.
We can create headings using hashtags, #
:
We can generate bulleted (un-numbered) using a space and hyphen:
Here is a list:
- Item 1
- This is item 2
- I'm item 3
We can also nest lists using additional spaces:
Here is a list with nested sub-lists:
- Item 1
- Item 2
- Item 2(a)
- Item 2(b)
- Item 2(c)
- Item 3
We can also create numbered lists using 1.
, 2.
, etc. Note: A numbered list will always be enumerated 1, 2, 3... regardless of how you've actually numbered the items.
Here is a numbered list:
- Item 1
- Item 2
- Item 3
- Item 6
Back to integers vs. floats¶
The normal division symbol /
will always return a floating point number.
6 / 3
2.0
Sometimes, we would prefer to return an integer number. We can this using the //
operation:
6 // 3
2
7 // 2
3
The integer division //
will always return the quotient from performing long division.
We can get the remainder from integer division using %
. This is called modular division.
7 % 2
1
This cell above shows that the remainder of dividing 7
by 2
is 1
.
101 // 43
2
101 % 43
15
The two cells above show that 100
divided by 42
has quotient 2
and remainder 16
. Let's check this:
43 * 2 + 15
101
Variable assignment in Python¶
Very often, we want to perform operations on some input that might change. We can define variables using the =
symbol:
num = 102
den = 43
We can recall the value of this variable with the variable name:
num
102
den
43
quot = num // den
rem = num % den
quot
2
rem
16
quot*den + rem
102