In [2]:
print 'Hello world!'


Hello world!

Getting started with python

We have done the following

  • Installed python programming language
  • Installed IPython notebook
  • Started ipython notebook
  • Create a new ipython notebook called "GettingStartedWithIPythonNotebook"

Create some variables


In [5]:
i = 10
print type(i)
f = 4.1
print type(f)


<type 'int'>
<type 'float'>

Advanced printing


In [8]:
print 'Our float number is %f. Our integer number is %d.' % (f, i)


Our float number is 4.100000. Our integer number is 10.

Conditional statement


In [11]:
if i == 10 and f > 4.0:
    print 'Lala!'
else:
    print 'Haha!'


Lala!

Loops


In [12]:
l = [3, 1, 2]

In [13]:
for element in l:
    print element


3
1
2

In [17]:
counter = 6
while counter < 10:
    print counter
    counter += 1


6
7
8
9

Creating functions in python


In [20]:
def add2(x):
    y = x + 2
    return y

i = 5
add2(i)


Out[20]:
7

In [22]:
# Lambda functions
square = lambda x: x**2
square(3)


Out[22]:
9