– Génie Logiciel – – Méthodes de programmation – (fascicule 7

Universit´
e de Picardie Jules Verne
L@RIA, Bat Curi, 5 rue du moulin neuf
80000 Amiens
– G´
enie Logiciel –
– M´
ethodes de programmation –
(fascicule 7: PYTHON)
Licence d’informatique
Christophe C´
erin
version 3.7 au 5/9/2003
page : 1
Introduction
http://www.python.org/
Python is an interpreted, interactive, object-oriented pro-
gramming language. It is often compared to Tcl, Perl,
Scheme or Java.
Il peut ˆ
etre vu comme un langage de scripts!
– Pythonhasmodules,classes,exceptions,veryhighlevel
dynamic data types, and dynamic typing. There are in-
terfaces to many system calls and libraries, as well as to
various windowing systems (X11, Motif, Tk, Mac, MFC).
New built-inmodulesareeasilywrittenin C orC++.Python
is also usable as an extension language for applications
that need a programmable interface.
Nosobjectifs: comparer(aumoyend’exemples)avecSML,
en particulier la couche objet.
page : 2
Les ´
el´
ements de base
[christophe@localhost licenc]$ python
Python 2.3a1 (#4, Jan 19 2003, 12:22:48)
[GCC 3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> help()
Welcome to Python 2.3! This is the online help utility.
If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://www.python.org/doc/tut/.
Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules. To quit this help utility and
return to the interpreter, just type "quit".
To get a list of available modules, keywords, or topics, type "modules",
"keywords", or "topics". Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given word
such as "spam", type "modules spam".
help>
page : 3
Les ´
el´
ements de base
[root@m11 Python-2.2.1]# /usr/local/bin/python
Python 2.2.1 (#1, Aug 20 2002, 09:56:09)
[GCC 2.96 20000731 (Mandrake Linux 8.1 2.96-0.62mdk)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> quit
’Use Ctrl-D (i.e. EOF) to exit.’
>>> quit
’Use Ctrl-D (i.e. EOF) to exit.’
>>> print ’bonjour’
bonjour
>>> 12 + 3
15
>>> x = 12 * 2
>>> x + 1
25
>>> a = 3
>>> b = 4
>>> b / 2 + a
5
>>> b / (2+a)
0
>>> b / (2.0 + a)
0.80000000000000004
>>> 999999999999999999999999999 + 1 # ATTENTION LONG INT en 2.2
1000000000000000000000000000L
>>> a = 4 ; b = 5
>>> a * b
20
>>> b % a
1>>> a % b
4
>>> print ’Le %s est %d’ % (’r´
esultat’,1)
Le r´
esultat est 1
page : 4
Les ´
el´
ements de base: condition
>>> a = b = c = 1
>>> print a, ’bonjour’, c
1 bonjour 1
>>> a = 1; b=1; # ceci est un commentaire
>>> if a == 1:
... print ’a vaut 1’
... elif a==2:
... print ’autre’ # il faut mettre une indentation
...
a vaut 1
>>> if 1<2<3: print ’Hello’
...
Hello
>>> if 1 < 2 and ’fifi’ == ’fifi’: print ’Okay’
...
Okay
>>> if not 5 == 5 or (1 < 2 and 3 != 4): print ’Hello’
...
Hello
>>>
1 / 55 100%

– Génie Logiciel – – Méthodes de programmation – (fascicule 7

La catégorie de ce document est-elle correcte?
Merci pour votre participation!

Faire une suggestion

Avez-vous trouvé des erreurs dans linterface ou les textes ? Ou savez-vous comment améliorer linterface utilisateur de StudyLib ? Nhésitez pas à envoyer vos suggestions. Cest très important pour nous !