# string interpolation
temp = 12
nom = "Alexis"
print("Bonjour {}, il fait {} degrés".format(nom, temp))
Bonjour Alexis, il fait 12 degrés
print(" {} ".format(1/3))
print(" {:.2f} ".format(1/3))
0.3333333333333333 0.33
equipe = ['Achmed', 'Rania', 'Sofiane', 'Asma', 'Chafik']
# premier element
equipe[0]
'Achmed'
equipe[1:4]
['Rania', 'Sofiane', 'Asma']
equipe[:3]
['Achmed', 'Rania', 'Sofiane']
equipe[5]
--------------------------------------------------------------------------- IndexError Traceback (most recent call last) <ipython-input-9-2d0b0099acee> in <module>() ----> 1 equipe[5] IndexError: list index out of range
equipe[-1]
'Chafik'
equipe[-2]
'Asma'
?equipe.append()
equipe.insert(2, "Alexis")
equipe
['Achmed', 'Rania', 'Alexis', 'Sofiane', 'Asma', 'Chafik']
vide = []
if len(vide) == 0:
print("la liste est vide")
la liste est vide
vide == []
True
not vide
True
vide == False
False
a = [1,2]
b = a
a[0] = 5
print(b)
[5, 2]
# avec copy
a = [1,2]
b = a.copy()
a[0] = 5
print(a)
print(b)
[5, 2] [1, 2]
phrase = "Il fait BEAU et CHaud Aujourd'hui"
[ m.lower() for m in phrase.split(' ') if len(m) > 3 ]
['fait', 'beau', 'chaud', "aujourd'hui"]
mots = []
liste_mots = phrase.split(' ')
for m in liste_mots:
if len(m) > 3:
mots.append(m.lower())
print(mots)
['fait', 'beau', 'chaud', "aujourd'hui"]
liste_mots = ['fait', 'beau', 'chaud', "aujourd'hui"]
print(' '.join(liste_mots))
fait beau chaud aujourd'hui
print('-'.join(liste_mots))
fait-beau-chaud-aujourd'hui