Hints to know


In [2]:
print("Hello man")


Hello man

Example code block

print("Hello man"

Example maths

$$ y = \frac{a}{b+c} $$$$ \int f(x) dx $$$$ \int f(x)\,dx $$

Detailed info for LaTex in jupyter

Timing code


In [1]:
def fibo(n):
    if n == 0:
        return 0
    elif n == 1:
        return 1
    return fibo(n-1) + fibo(n-2)

In [2]:
%timeit fibo(20)


100 loops, best of 3: 4.63 ms per loop

Note: Also it's possible to use %%timeit for the whole code block

Plotting


In [9]:
%matplotlib inline
%config InlineBackend.figure_format = 'retina'

import matplotlib.pyplot as plt
import numpy as np

In [10]:
x = np.linspace(0, 1, 300)
for w in range(2, 6, 2):
    plt.plot(x, np.sin(np.pi*x)*np.sin(2*w*np.pi*x))


Debugging with %pdb


In [11]:
%pdb


Automatic pdb calling has been turned ON

In [ ]:
numbers = "hello"
sum(numbers)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-12-7503c0bfb974> in <module>()
      1 numbers = "hello"
----> 2 sum(numbers)

TypeError: unsupported operand type(s) for +: 'int' and 'str'
> <ipython-input-12-7503c0bfb974>(2)<module>()
      1 numbers = "hello"
----> 2 sum(numbers)

ipdb> pdb.pm()
*** NameError: name 'pdb' is not defined
ipdb> print(numbers)
hello