tdn2.py

Created by emiledu90

Created on March 29, 2023

1.88 KB


#exercice 1 td2
maListe=[22,"coucou",33,"z",'a','b',111,99]
print(maListe)
maListe[3]=1024

uneListe=['z','a','d','aa']


>>> (executing cell "" (line 1 of "exercice 1 td2.py"))
[22, 'coucou', 33, 'z', 'a', 'b', 111, 99]

>>> len(ma_Liste)
8

>>> (executing cell "" (line 1 of "exercice 1 td2.py"))
[22, 'coucou', 33, 'z', 'a', 'b', 111, 99]

>>> len(ma_Liste)
8

>>> 'z' in maListe

>>> (executing lines 2 to 4 of "exercice 1 td2.py")
[22, 'coucou', 33, 'z', 'a', 'b', 111, 99]

>>> len(maListe)
8

>>> 'z' in maListe
False

#exercice 2 td2
>>> maListe
[22, 'coucou', 33, 1024, 'a', 'b', 111, 99]

>>> maListe.append(33)

>>> maListe.append(33)

>>> maListe.append("hello")

>>> maListe
[22, 'coucou', 33, 1024, 'a', 'b', 111, 99, 33, 'hello']

>>> maListe.remove(33)

>>> 33 in maListe
True

>>> maListe
[22, 'coucou', 1024, 'a', 'b', 111, 99, 33, 'hello']

>>> maListe.pop()
'hello'

>>> maListe.pop(1)
'coucou'

>>> maListe
[22, 1024, 'a', 'b', 111, 99, 33]

>>> maListe.index('a')
2

>>> maListe.index(111)
4

>>> maListe.sort()

>>> maListe.remove('a')

>>> maListe.remove('b')

>>> maListe
[22, 1024, 111, 99, 33]

>>> maListe.sort()

>>> maListe
[22, 33, 99, 111, 1024]

>>> (executing cell "" (line 1 of "exercice 1 td2.py"))
[22, 'coucou', 33, 'z', 'a', 'b', 111, 99]

>>> uneListe.sort()

>>> uneListe
['a', 'aa', 'd', 'z']

maListe=[22,"coucou",33,"z",'a','b',111,99]

>>> maListe[0:3]
[22, 'coucou', 33]

>>> maListe[0:4:2]
[22, 33]

>>> maListe[0:3]
[22, 'coucou', 33]

>>> maListe[:]
[22, 'coucou', 33, 'z', 'a', 'b', 111, 99]

>>> maListe[::2]
[22, 33, 'a', 111]

>>> maListe[::-1]
[99, 111, 'b', 'a', 'z', 33, 'coucou', 22]

>>> maListe[O]

>>> maListe[0]
22

>>> maListe[-1]
99

>>> maListe[:3]
[22, 'coucou', 33]

>>> maListe[2:]
[33, 'z', 'a', 'b', 111, 99]

>>> maListe[-1]="b"

>>> maListe
[22, 'coucou', 33, 'z', 'a', 'b', 111, 'b']

#exercice 7 td2
L=[0,1,2,3]
m=(L[0]+L[1]+L[2]+L[3])

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.