{ "metadata": { "name": "00_intro" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Python for beginners" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Everything in python is an object." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "An object contains attributes, some of this attributes are callable and are called method.\n", "Are called function the callable attributes of the \"module\" objects." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Today I will present:\n", "\n", "* data types;\n", "* syntax;\n", "* some useful library\n", "\n", "Before to start you need to open a terminal, moving inside the directory with\n", "\n", " $ cd doc/python/\n", "\n", "and type:\n", " \n", " $ ipython notebook --pylab inline\n", "\n", "You can modify the code inside the cell and execute with: \"Shift + Enter\" or with \"Ctrl + Enter\" or using the \"play\" icon above" ] }, { "cell_type": "code", "collapsed": false, "input": [ "2 + 2" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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](http://pypi.python.org/pypi)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "After you have insalled python before use function and object of a library you need to load the library inside your program:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "import this" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Then you can start using variables that are defined inside, like:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "this.c" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "print this.s" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Other ways to import things in python are:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "import os, sys, time, math # import more than one library at the same time" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "import numpy as np # import a library changing its name" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "from timer import Timer # import only one thing from a library" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "from math import * # import all function and variables from the math library..." ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }