Aller au contenu principal
🔒 Mode aperçu. Les quinze premières leçons Foundations sont gratuites ; celle-ci est Pro. Démarrez un trial de 7 jours pour débloquer l'éditeur, les conseils AI et le reste du programme. Carte requise, annulez à tout moment dans Dashboard.Démarrer le trial de 7 jours →
← CoursPython FoundationsModule 8 · Python moderne et synthèsefunctools.singledispatch — répartition basée sur le typewrite161 / 174
+100 XP
Tâche🌐 shown in EN
📝 **Question:** Build a \`length(x)\` using \`@singledispatch\` that returns:\n- for str: \`len(x) * 2\`\n- default (any other type): \`-1\`\nPrint \`length("hi")\` and \`length(42)\`.\nExpected:\n4\n-1 📋 Pick the right answer. 💡 **Hint:** Re-read the theory above if unsure.
✏️ Écris ton code ici
🐍
Chargement de Python...
Téléchargement unique (~1 Mo). Ensuite, c’est instantané.
📊 Résultat
Cliquez sur Exécuter pour voir le résultat...