Python for beginners

Everything in python is an object.

An object contains attributes, some of this attributes are callable and are called method. Are called function the callable attributes of the "module" objects.

Today I will present:

  • data types;
  • syntax;
  • some useful library

Before to start you need to open a terminal, moving inside the directory with

$ cd doc/python/

and type:

$ ipython notebook --pylab inline

You can modify the code inside the cell and execute with: "Shift + Enter" or with "Ctrl + Enter" or using the "play" icon above

In [ ]:
2 + 2

Python have a huge library, therefore before to start to implement something you should check that it is not already implemented, moroever a lot of software is available outside the standard library have a look to the: Python Package Index

After you have insalled python before use function and object of a library you need to load the library inside your program:

In [ ]:
import this

Then you can start using variables that are defined inside, like:

In [ ]:
this.c
In [ ]:
print this.s

Other ways to import things in python are:

In [ ]:
import os, sys, time, math    # import more than one library at the same time
In [ ]:
import numpy as np  # import a library changing its name
In [ ]:
from timer import Timer  # import only one thing from a library
In [ ]:
from math import *   # import all function and variables from the math library...
In [ ]: