2

"a string"

None

{ 'y': 3, 'x': 5}

"""
Explanation: Rich Output
In the notebook format you are not limited to console output. In this example
we'll generate more interesting things in Python for inclusion in the
notebook.
Values
The simplest form of output is the evaluation value of the cell.
This is very similar to the regular Python interactive
read-eval-print-loop. Built-in data types have familiar
representations. None is not shown.
End of explanation
"""


print('Hello, world')

print("Hey, what's my value?")
42

"""
Explanation: Print
You can also print strings to the output. Notice that the Out[] label
is shown for the evaluation value, not any printed output.
End of explanation
"""


class Thing:
    def __init__(self, x):
        self.x = x

Thing(3)

"""
Explanation: Value representation
If you do not specify a way to represent custom values, they appear
using the default Python representation which shows the class and
a memory location.
End of explanation
"""


class Thing:
    def __init__(self, x):
        self.x = x
    def __repr__(self):
        return 'Thing({})'.format(self.x)

Thing(3)

"""
Explanation: The __repr__ function can be defined for your class to provide a
string representation.
End of explanation
"""


from IPython.display import HTML
HTML('<span style="color: #000; background-color: #f00;">bold</span>')

print('<h1>I wanna be big</h1>')

"""
Explanation: HTML
Code cells can produce HTML output directly using the IPython.display
module. Notice that HTML display objects must be used, print cannot
produce HTML in the output area.
End of explanation
"""


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)

"""
Explanation: HTML representation
Just like with strings, custom Python objects can define a method
_repr_html_ that lets them be shown using HTML in the output.
End of explanation
"""


from IPython.display import Image

pineapple = Image('../../images/Pineapple-256.png')
pineapple

"""
Explanation: Images
Use the Image class from IPython.display to work with PNG or JPEG images.
End of explanation
"""


flower = Image(url='http://i.imgur.com/RmIUQ7R.jpg', embed=True)
flower

"""
Explanation: The default working directory is the directory containing your notebook file.
You can also load images from the internet.
(Photo below by Aaron Burden).
End of explanation
"""


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

"""
Explanation: Embed
For media such as images included by URL, the default behavior is for the saved notebook to only
include a reference to the online data. When the notebook is reopened the image will be
fetched following the URL. To save a copy of the media in the notebook you can add the embed=True
option.
Audio
You can also turn arrays of numbers into audio data. An Audio object contains audio data and
metadata about mono/stereo, sample format and playback framerate. In this example we use numpy
to do phase modulation.
End of explanation
"""


