[Python-de] Re: (no subject)
Gerhard Häring
gerhard.haering at opus-gmbh.net
Wed Oct 9 13:01:07 EDT 2002
Josef Cihal <josef.cihal=QejgLEES/+Q at public.gmane.org> [2002-10-09 11:42 GMT]:
> geht etwas ähnliches einfacher in Python zu schreiben?
>
> if a=None:
Mit None vergleicht man am besten mit dem "is" Operator: a is None
> h=10
> elsif a= 1
> k=20
> else:
> k=10
Wenn du auch im Fall "a is None" die Variable 'k' und nicht 'h' setzen
wolltest, dann ginge eine Lösung mit Dictionary und der get-Methode von
Dictionaries:
mapping = {None: 10, 1: 20}
key = 1
k = mapping.get(key, 10)
^ ^
Schlüssel --+ +-- Default-Wert
HTH,
-- Gerhard
More information about the Python-de
mailing list