Zum Hauptinhalt springen
🔒 Vorschaumodus. Die ersten fünfzehn Foundations-Lektionen sind kostenlos; diese hier ist Pro. Starte einen 7-Tage-Trial, um den Editor, AI-Hinweise und den Rest des Lehrplans freizuschalten. Karte erforderlich, jederzeit im Dashboard kündbar.7-Tage-Trial starten →
← KurseSenior Deep-DivesModul 4 · Speicher, Profilierung, OptimierungVorhersage: Bytecode-Introspektion mit „dis“.predict63 / 161
+100 XP
Aufgabe
📝 **Frage:** Welche Funktion hat nach konstanter Faltung WENIGER Bytecode-Operationen: „def add(a, b): return a + b“ oder „def add_const(): return 1 + 2“? 📋 Wählen Sie die richtige Antwort. 💡 **Hinweis:** Lesen Sie die obige Theorie noch einmal, wenn Sie sich nicht sicher sind.
Sage die Ausgabe vorher

Lies den Code sorgfältig

import dis

def add(a, b):
    return a + b

def add_const():
    return 1 + 2

# Imagine running:
#     dis.dis(add)
#     dis.dis(add_const)
#
# Which body compiles to FEWER bytecode ops once CPython's peephole
# / constant-folding passes are done?
#
# Print the name of the winning function: 'add' or 'add_const'.
# Type your prediction.

Was wird das Programm ausgeben? Schreib hier:

💬 Diskussion

Sei der erste — stelle eine Frage oder teile einen Tipp.
Anmelden um an der Diskussion teilzunehmen. Lesen ist kostenlos.
Diskussion wird geladen…