In [1]:
2
Out[1]:
In [2]:
"a string"
Out[2]:
In [3]:
None
In [4]:
{ 'y': 3, 'x': 5}
Out[4]:
In [5]:
print('Hello, world')
In [6]:
print("Hey, what's my value?")
42
Out[6]:
In [7]:
class Thing:
def __init__(self, x):
self.x = x
Thing(3)
Out[7]:
The __repr__
function can be defined for your class to provide a
string representation.
In [8]:
class Thing:
def __init__(self, x):
self.x = x
def __repr__(self):
return 'Thing({})'.format(self.x)
Thing(3)
Out[8]:
In [9]:
from IPython.display import HTML
HTML('<span style="color: #000; background-color: #f00;">bold</span>')
Out[9]:
In [10]:
print('<h1>I wanna be big</h1>')
In [11]:
class Thing:
def __init__(self, x):
self.x = x
def _repr_html_(self):
''' Fancy shadow effect '''
style = 'text-shadow: 1px 2px 0 #888;'
return 'Thing(<span style="{}">{}</span>)'.format(style, self.x)
Thing(3)
Out[11]:
In [12]:
from IPython.display import Image
pineapple = Image('../../images/Pineapple-256.png')
pineapple
Out[12]:
The default working directory is the directory containing your notebook file.
You can also load images from the internet.
(Photo below by Aaron Burden).
In [13]:
flower = Image(url='http://i.imgur.com/RmIUQ7R.jpg', embed=True)
flower
Out[13]:
In [14]:
from IPython.display import Audio
import numpy as np
framerate = 8000
seconds = 3.0
frames = framerate * seconds
x = np.linspace(0, seconds, frames)
freq = 440.0 * 4.0
fmult = 1.5
mod = np.linspace(2.0, -2.0, frames)
freq2 = freq * fmult
y = np.sin(x * freq + mod * np.sin(x * freq2));
sound = Audio(data=y, rate=framerate)
sound
Out[14]: