a = 3
a
b = 89
def sq(x):
return x * x
sq(b)
print
import sys
print("Error !!", file=sys.stderr)
"Hello"
def dummy_function():
import missing_module
dummy_function()
tab
to see what is available in sys
module¶from sys import
?print
shift+tab
¶print(
name = input('Enter your name: ')
'Hello, ' + name
class Person:
def __init__(self, name="John Doe", address="Paris", picture=""):
self.name = name
self.address = address
self.picture = picture
def _repr_mimebundle_(self, include=None, exclude=None):
return {
"text/html": """<img src="{}">
<div><i class='fa-user fa'></i>: {}</div>
<div><i class='fa-map fa'></i>: {}</div>""".format(self.picture, self.name, self.address)
}
james = Person("James Smith", "Boston")
display(james)
marie = Person("Marie Curie", "Poland", "./marie.png")
display(marie)
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
plt.plot(np.sin(np.linspace(0, 20, 100)));
%matplotlib widget
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
plt.plot(np.sin(np.linspace(0, 20, 100)));
from ipywidgets import IntSlider
slider = IntSlider()
slider
slider.value
slider
slider.value = 36
from ipywidgets import interact
@interact
def foo(x = ['a', 'b'], n=(1, 10)):
print(x * n)
from ipywidgets import Video
video = Video.from_file("Big.Buck.Bunny.mp4")
video
import matplotlib
matplotlib.use("agg")
try:
from urllib.request import urlretrieve
except ImportError:
from urllib import urlretrieve
import os
import itk
from itkwidgets import view
# Download data
file_name = '005_32months_T2_RegT1_Reg2Atlas_ManualBrainMask_Stripped.nrrd'
if not os.path.exists(file_name):
url = 'https://data.kitware.com/api/v1/file/564a5b078d777f7522dbfaa6/download'
urlretrieve(url, file_name)
image = itk.imread(file_name)
view(image)
from IPython.display import clear_output, display, update_display
from time import sleep
class Square:
color = 'PeachPuff'
def _repr_html_(self):
return '''
<div style="background: %s; width: 200px; height: 100px; border-radius: 10px;">
</div>''' % self.color
square = Square()
display(square, display_id='some-square')
square.color = 'OliveDrab'
update_display(square, display_id='some-square')
print("hello")
sleep(3)
clear_output() # will flicker when replacing "hello" with "goodbye"
print("goodbye")
print("hello")
sleep(3)
clear_output(wait=True) # prevents flickering
print("goodbye")
from IPython.display import HTML
HTML('''
<div style="background: aliceblue; width: 200px; height: 100px; border-radius: 10px;">
</div>''')
from IPython.display import Math
Math(r'F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx')
from IPython.display import Latex
Latex(r"""\begin{eqnarray}
\nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} & = \frac{4\pi}{c}\vec{\mathbf{j}} \\
\nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho \\
\nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\
\nabla \cdot \vec{\mathbf{B}} & = 0
\end{eqnarray}""")
from IPython.display import SVG
SVG(url='https://jupyter.org/assets/main-logo.svg')
from IPython.display import SVG
SVG(filename='./logo.svg')
from time import sleep
from IPython.display import ProgressBar
for i in ProgressBar(10):
sleep(0.1)
from IPython.display import JSON
JSON(['foo', {'bar': ('baz', None, 1.0, 2)}], metadata={}, expanded=True, root='test')
from IPython.display import GeoJSON
GeoJSON(
data={
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [11.8, -45.04]
}
}, url_template="http://s3-eu-west-1.amazonaws.com/whereonmars.cartodb.net/{basemap_id}/{z}/{x}/{y}.png",
layer_options={
"basemap_id": "celestia_mars-shaded-16k_global",
"attribution" : "Celestia/praesepe",
"tms": True,
"minZoom" : 0,
"maxZoom" : 5
}
)