You are on page 1of 18

Python

Session 1: introduction to Python


Jos Dapena Paz <jdapena@igalia.com>

Sessions

Session 1:

Presentation of language, brief history and practical


examples of language structures.

Session 2:

Important projects

Standard libraries

Other modules

irst session contents

!"hat#s Python$

%rief history

Properties

&ocumentation !"here$

Introduction to the language

Installation and usage

Practical examples

!"hat#s Python$

What's Python?

%rief history

Properties

&ocumentation !"here$

Introduction to the language

Installation and usage

Practical examples

!"hat#s Python$

'igh le(el language

)uthor: *uido +an ,ossum -first release in


1..1/

0mphasis on readability.

Priority: easy for programmer, then, computer.

1inimalist language. "ide libraries.



'istory

)uthor: *uido +an ,ossum. 2"I.

%egins Python at the end of 34#s. Inspired in


)%2 language.

irst release in 1..1.

*uido +an ,ossum: %ene(olent &ictator or


5ife

2ronology

1..1: 1st release. 2lasses, inheritance,


exceptions, modules and basic types list,
dict y str

1..6: 1.4. %asic functional programming


-lambda methods/.

2441: 1.7.1 y 2.1. *P5 compatible license.

Python 2.2. )ll types are unified. )ll are classes.

uturr: Python 8444 -8.4/ in 2443.



Python is free soft9are

rom Python 2.2, Python oundation Soft9are


5icense, *P5:compatible.

)ll code is property of Python oundation.

Python community sho9 a (ery high acti(ity:

'undreds of modules;extensions a(ailable.

5ots of soft9are a(ailable implemented in Python.

Python is the language of 244< -language =IO%0,


Python had biggest increase of usage/.

&ocumentation

Python is (ery 9ell documented


http:;;docs.python.org

=utorial: http:;;docs.python.org;tut;

5anguage reference: -for language la9yers/:


http:;;docs.python.org;ref;

5ibrary reference: http:;;docs.python.org;lib;



irst session contents

!"hat#s Python$

%rief history

Properties

&ocumentation !"here$

Introduction to the language

Installation and usage

Practical examples

Installation and running
In ubuntu, install Python pac>age:
+ery useful to install online documentation:
$ sudo apt-get install python
$ sudo apt-get install python-doc

Python shell

Python is an interpreted language.

1odes:

Interacti(e

ile

2ommand line

0xecutable

1odo interacti(o
?ust run Python, and add commands and
statements in the shell
$ python
Python 2.5.1 (r251:54863, ct 5 2!!", 13:36:32#
$%&& 4.1.3 2!!"!'2' (prerelease# (()untu
4.1.2-16u)untu2#* on linu+2
,ype -help-, -copyright-, -credits- or -license- .or /ore
in.or/ation.
000 111
2
000 a 2 3hola3
000 a
4hola4
000 print a
hola

Shell mode help
"hith dir -/ command 9e get the methods
a(ailable.
"ith help -/ command 9e get the help of a class
or instance.
000 dir (a# 5 6ith instances
000 dir (list# 5 6ith classes
000 help (a# 5 6ith instances (no strings#
000 help (list# 5 6ith classes

Python as a calculator

%asic types:

Integers

loats and complex numbers

Strings

)sign

@ (ariable

5ists. ,anges, asigns by range, operators.



2ontrol flo9 structures

"hile. Indentation in Python

If, If:0lif:0lse

or, range.

%rea>, continue, else, pass

unctions. &efinition.

2lasses

1ore flo9 control structures

5ist methods. =he list as a Aueue and as a


stac>.

1ap, reduce, filter

5ist comprehensions

&el

Other seAuences: tuples. &ictionaries

5ooping

2onditions, conditions in seAuences.



1odules

1odules reference

0xamples: iles api -ile objects/, http api


-urllib2/

You might also like