Python Introduction
Python Introduction
Chaine d’interprétation
Technique de production de Python
>>> d
{1: 'hello', 2: 'there', 10: 'world'}
>>> del(d[2])
>>> d
{1: 'hello', 10: 'world'}
• The built-in list >>> l1 = [1] >>> d = {1 : 10}
function will copy >>> l2 = list(l1) >>> d2 = d.copy()
a list >>> l1[0] = 22 >>> d[1] = 22
>>> l1 >>> d
• The dictionary has [22] {1: 22}
a method called >>> l2 >>> d2
copy [1] {1: 10}
• Lists, Tuples, and Dictionaries can store any type
(including other lists, tuples, and dictionaries!)
• Only lists and dictionaries are mutable
• Integers: 2323, 3234L
• Floating Point: 32.3, 3.1E2
• Complex: 3 + 2j, 1j
• Lists: l = [ 1,2,3]
• Tuples: t = (1,2,3)
• Dictionaries: d = {‘hello’ : ‘there’, 2 : 15}
• 0 and None are false
• Everything else is true
• True and False are aliases for 1 and 0
respectively
• Compound boolean expressions >>> True and False
short circuit False
• and and or return one of the >>> False or True
elements in the expression True
>>> 7 and 14
• Note that when None is returned 14
the interpreter does not print >>> None and 2
anything >>> None or 2
2
inflobj = open(‘data’, ‘r’) Open the file ‘data’ for input
In file ifstatement.py
>>> import whileloop
x=1 1
while x < 10 : 2
print x 3
x=x+1 4
5
6
In whileloop.py
7
8
9
>>>
In interpreter
for x in [1,7,13,2] : for x in range(5) :
forloop1.py forloop2.py print (x)
print (x)