Python

Python est un langage de programmation interprété, généraliste et open-source, créé par Guido van Rossum en 1991. Sa philosophie : un code lisible, simple et expressif.

Caractéristiques principales

Synthaxe rapide

# Variables (pas de déclaration de type)
nom = "Python"
version = 3.12

# Condition
if version >= 3:
    print("Version moderne")

# Fonction
def saluer(nom: str) -> str:
    return f"Bonjour, {nom} !"

print(saluer("monde"))

# Listes, dicts, sets, tuples
fruits = ["pomme", "banane", "cerise"]
config = {"host": "localhost", "port": 8080}

# Boucle
for fruit in fruits:
    print(fruit)

# Compréhension de liste
carres = [x**2 for x in range(10)]

Usages principaux


Domaine Outils / Frameworks
Web Django, FastAPI, Flask
Data Science Pandas, NumPy, Matplotlib
Machine Learning PyTorch, TensorFlow, Scikit-learn
IA / LLM LangChain, Transformers, OpenAI SDK
Automatisation Selenium, Playwright, scripts
DevOps / Cloud Ansible, Terraform (SDK), AWS Boto3
Cybersécurité Scapy, pwntools, Metasploit modules
IoT MicroPython, CircuitPython

Concepts clés

Classes & OOP

class Animal:
    def __init__(self, nom: str):
        self.nom = nom

    def parler(self) -> str:
        return f"{self.nom} fait un bruit"

class Chien(Animal):
    def parler(self) -> str:
        return f"{self.nom} aboie !"

chien = Chien("Rex")
print(chien.parler())  # Rex aboie !

Décorateur

def log(func):
    def wrapper(*args, **kwargs):
        print(f"Appel de {func.__name__}")
        return func(*args, **kwargs)
    return wrapper

@log
def addition(a, b):
    return a + b

Générateurs

def fibonacci():
    a, b = 0, 1
    while True:
        yield a
        a, b = b, a + b

gen = fibonacci()
print([next(gen) for _ in range(8)])
# [0, 1, 1, 2, 3, 5, 8, 13]

Async / Await

import asyncio

async def fetch_data(url: str):
    await asyncio.sleep(1)  # simulation requête
    return f"Données de {url}"

async def main():
    result = await fetch_data("https://api.example.com")
    print(result)

asyncio.run(main())

Écosystème & outils


Outil Rôle Outil Rôle
pip Gestionnaire de paquets pytest Tests
venv / virtualenv Environnements virtuels mypy Vérification de types statique
Poetry Gestion deps + packaging moderne ruff / black Linting & formatage
pyenv Gestion des versions Python Jupyter Notebooks interactifs

Versions


Version Statut
Python 2.x EOL depuis 2020
Python 3.10 Match/case (pattern matching)
Python 3.11 +60% de performances
Python 3.12 Actuelle stable
Python 3.13 Free-threaded (GIL optionnel)

Avantages & Inconvénients


Python vs autres langages


En résumé : Python est le langage le plus polyvalent aujourd’hui, incontournable en Data Science et IA, très solide en web backend, et parfait pour automatiser ou prototyper rapidement.