Monday, August 24th, 2026¶

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, or b to add a cell below.
  • We can delete a cell by selecting the cell, then hitting d, d.
In [4]:
1 + 2
Out[4]:
3
In [2]:
7 / 6
Out[2]:
1.1666666666666667
In [3]:
4 - 7
Out[3]:
-3

Arithmetic operations¶

Addition:

In [5]:
1 + 3
Out[5]:
4

Subtraction:

In [6]:
6 - 11234
Out[6]:
-11228

Multiplication:

In [7]:
6 * 7
Out[7]:
42

Division:

In [8]:
10 / 2
Out[8]:
5.0

Exponentiation:

In [9]:
10^2
Out[9]:
8

To perform exponentiation, use ** or the pow function instead of ^:

In [10]:
10**2
Out[10]:
100
In [11]:
2**5
Out[11]:
32

Using the standard division / will return what is called a float.

In [12]:
10 / 2
Out[12]:
5.0
In [13]:
10 * 2
Out[13]:
20

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.
In [14]:
12345678901234567890
Out[14]:
12345678901234567890
In [15]:
12345678901234567890.
Out[15]:
1.2345678901234567e+19

Because they are approximations, floating point numbers have some limitations...

In [16]:
12345678901234567890 + 1
Out[16]:
12345678901234567891
In [17]:
12345678901234567890. + 1
Out[17]:
1.2345678901234567e+19
In [18]:
2**1200
Out[18]:
17218479456385750618067377696052635483579924745448689921733236816400740691241745619397484537236046173286370919031961587788584927290816661024991609882728717344659503471655990880884679896520055123906467064419056526231345685268240569209892573766037966584735183775739433978714578587782701380797240772477647874555986712746271362892227516205318914435913511141036261376
In [19]:
2.0 ** 1200
---------------------------------------------------------------------------
OverflowError                             Traceback (most recent call last)
Cell In[19], line 1
----> 1 2.0 ** 1200

OverflowError: (34, 'Result too large')

Markdown¶

Markdown is a markup language used for creating formatted text. In Jupyter, we create Markdown cells to hold this text.

A Code cell can be converted to a Markdown cell using the dropdown menu in the top menu bar. Alternatively, we can select a Code cell and hit the M key to convert it to a Markdown cell. To convert back to a Code cell, we can again use the dropdown menu or select the cell and hit the Y key.

Once we've written our desired Markdown, we can execute the cell (e.g. by hitting SHIFT + ENTER) to render the Markdown. If we need to edit the Markdown cell, we can double click on it, or select the cell and hit ENTER.

In [21]:
5 * 2
Out[21]:
10
In [ ]:
This is a code cell. Anything in here is treated as Python code. Because this is not valid Python code, it will give an error.

Notice that some of the text is colored green. These parts are built-in Python code.
Also notice that the font is uniform width, that is, each character has the same width.

This is a Markdown cell. Anything in here is treated as text. Notice that the font is not uniform width and is generally easier to read. The cell also wraps text to a new line if it exceeds the visual width.

Within a Markdown cell, We can create headings using hashtags, #, as demonstrated in the Markdown cell below. Double-click the cell and edit the heading text.

MTH 337 - First day of Markdown¶

Sub-headings (and sub-sub-headings, etc.) can be created using multiple hashtags, ## (or ###, etc.).

This is a sub-heading¶

This is a sub-sub-heading¶

This is a sub-sub-sub-heading¶

Markdown lists¶

We can generate bulleted (un-numbered) using a space and hyphen:

Here is a list:

  • This is item 1
  • This is item 2
  • This item 3

This is outside of the list.

Exercise: Add a Markdown cell below this one. Then, create a bulleted list of your three favorite TV shows or movies.

Reminders:

  • You can add a code cell below by selecting this cell and either hitting the a key or by clicking the + symbol in the top toolbar.
  • You can convert a code cell into a Markdown cell using the dropdown menu in the top toolbar, or by selecting the cell and hitting the m key.

Favorite movies:

  • Batman: Mask of the Phantasm
  • The Lord of the Rings: The Fellowship of the Ring
  • Hot Fuzz

We can also nest lists using additional spaces.

Exercise: Modify your list of TV shows or movies as follows. Under each show/movie, create a nested sub-list of its main characters.

Favorite movies:

  • Batman: Mask of the Phantasm
    • Kevin Conroy
    • Mark Hamill
  • The Lord of the Rings: The Fellowship of the Ring
    • Ian McKellan
    • Viggo Mortenson
    • Elijah Wood
  • Hot Fuzz
    • Simon Pegg
    • Nick Frost

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.

Exercise: Modify the nested sub-lists of characters to be numbered, in order from favorite character to least.

Favorite movies:

  1. Batman: Mask of the Phantasm
    • Kevin Conroy
    • Mark Hamill
  2. The Lord of the Rings: The Fellowship of the Ring
    • Ian McKellan
    • Viggo Mortenson
    • Elijah Wood
  3. Hot Fuzz
    • Simon Pegg
    • Nick Frost

Back to integers vs. floats¶

The normal division symbol / will always return a floating point number. That is, a/b will return the closest floating point number to $\frac{a}{b}$.

In [23]:
4/3
Out[23]:
1.3333333333333333

Sometimes, we would prefer to return an integer number. In those cases, we can this using the // operation. The integer division // will always return the quotient from performing long division. That is, a//b will return the largest integer less than or equal to $\frac{a}{b}$ (e.g. by dropping the decimal portion).

In [25]:
10 / 2
Out[25]:
5.0
In [24]:
10 // 2
Out[24]:
5
In [26]:
7 // 3
Out[26]:
2
In [27]:
-7 // 3
Out[27]:
-3

Another way to think of integer division is by relating it to long division. Recall that For any integers $a$ and $b\not=0$, there are unique integers $q$ (the quotient) and $r$ (the remainder) such that $$a = b\cdot q + r \qquad \text{with} \qquad 0 \leq r < b.$$ For example, by performing long division to divide $100$ by $7$, we find that the quotient is $14$ and the remainder is $2$. That is, $100 = 7\cdot 14 + 2$.

In Python, the quotient $q$ can be found by performing integer division //. Similarly, can get the remainder $r$ using the modulus operator, %. This is called modular division.

In [28]:
100 // 7
Out[28]:
14
In [29]:
100 % 7
Out[29]:
2

Let's check that Python has correctly found the quotient and remainder.

In [ ]: