Seite 1 von 1

switch case, select case Kontrollstruktur bei python?

Verfasst: Freitag 13. Oktober 2006, 14:17
von 7crystal7
Hi Leute,

ich als alter VB und ab und zu Java Programmierer bin diese meiner Meinung nach tolle Kontrollstruktur sehr gewohnt und habe in python noch nichts äquivalentes gefunden, gibt es da etwas das man wissen müsste?! :-)

gruß
danke
babsi

Verfasst: Freitag 13. Oktober 2006, 14:24
von Rebecca
Python Tutorial hat geschrieben:Perhaps the most well-known statement type is the if statement. For example:

>>> x = int(raw_input("Please enter an integer: "))
>>> if x < 0:
... x = 0
... print 'Negative changed to zero'
... elif x == 0:
... print 'Zero'
... elif x == 1:
... print 'Single'
... else:
... print 'More'
...

There can be zero or more elif parts, and the else part is optional. The keyword `elif' is short for `else if', and is useful to avoid excessive indentation. An if ... elif ... elif ... sequence is a substitute for the switch or case statements found in other languages.
Alles klar?

Verfasst: Freitag 13. Oktober 2006, 14:28
von 7crystal7
oh, naja schade, dann wird wohl viel mit elif usw. programmiert :-/

Verfasst: Freitag 13. Oktober 2006, 14:33
von Zap
Ich war auch mal auf der Suche nach sowas, es gibt auch sehr elegante
Lösungen mit dictionaries.
Kannst du dir vielleicht mal diesen Wiki-Eintrag angucken:
Why isn't there a switch or case statement in Python?

Verfasst: Freitag 13. Oktober 2006, 14:45
von 7crystal7
danke, werde ich machen :)