---
# System prepended metadata

title: Les dictionnaires

---

# Les dictionnaires
```python=

# initialisation a vide
dico1 = {}
print(dico1)
dico2 = dict()
print(dico2)
# initialisation non vide
dico2 = {"Maths" : 12, "Fr" : 14, "EN" : 11}
print(dico2)
# ajout d'elements
dico2["Espagnol"] = 16
print(dico2)
print(dico1.fromkeys([1,2,3,4])) # ajout des cles à partir d'un itérable
print(dico1)
dico2.update({"Physique":7})
print(dico2)
# recuperation des cles d'un dictionnaire
print(dico2.keys())
print(list(dico2.keys()))
# recuperation des valeurs d'un dico
print(dico2.values())
print(list(dico2.values()))
print(dico2.get("Physique"))
print(dico2.get(7))
# suppression d'elements
print("*****", dico2.pop("EN"))
print(dico2)
#print(dico2.pop())
print(dico2)
# suppression d'un dico en entier
dico2.clear()
print(dico2)
# recuperation des couples cle/valeur
'''print(dico2.item())
print(list(dico2.item()))
'''
```
# Initialisation d'un tuple
```python=
monTuple = ("toto", 15, 15, True)
print(monTuple)
print(monTuple.count(15)) #nb d'occurences de 15
print(monTuple.index(15)) #position de 15

#test
dico3 = {"toto" : 15, "titi" : 10}
dico4 = list(dico3.items())
print(dico3.items())
```
# Les allias
```python=
l1 = [1,2,3]
l2 = l1
print(l1,l2)
l2.append(5)
print(l1,l2)
# l2 est un allias de l1
l3 = l1.copy()
l3.append(6)
print(l1, l2, l3)
```