Skip to Content
Programmieren von Kopf bis Fuß
book

Programmieren von Kopf bis Fuß

by David Griffiths, Paul Barry
April 2010
Beginner to intermediate
440 pages
9h 7m
German
O'Reilly Verlag
Content preview from Programmieren von Kopf bis Fuß

Die beiden Rabattfunktionen haben den gleichen Namen

Hier ist das gerade von Ihnen erstellte Modul promotion.py:

def rabatt(preis):
    return 0.9 * preis

Und hier ist das Modul sternback.py:

# Offizielles Sternback-Rabattmodul
# Copyright(c) Sternback & Co.
# Alle Rechte vorbehalten.
# Berechnet einen Rabatt von 5% auf einen Preis
def rabatt(preis):
    return 0.95 * preis

Beide Module definieren eine Funktion namens rabatt(). Was also passiert, wenn Sie versuchen, sie zu nutzen? Was macht Python, wenn es eine Zeile wie diese sieht:

preis_neu = rabatt(1.75)

Welche Funktion ruft es auf? Unseren Promo-Rabatt? Den Sternback-Rabatt? Beide? Keine???

Das ist eins der Probleme beim Teilen von Code. Gelegentlich gibt es in Modulen Funktionen mit dem gleichen Namen ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Softwareentwicklung von Kopf bis Fuß

Softwareentwicklung von Kopf bis Fuß

Dan Pilone, Russ Miles
Netzwerke von Kopf bis Fuß

Netzwerke von Kopf bis Fuß

Al Anderson, Ryan Benedetti

Publisher Resources

ISBN: 9783868993127Purchase bookSupplemental Content