I'm working on a project which used a load of If, Elif, Elif, ...Else structures, which I later changed for switch-like statements, as shown here and here.
How would I go about adding a general "Hey, that option doesn't exist" case similar to an Else in an If, Elif, Else statement - something that gets executed if none of the Ifs or Elifs get to run?
If the else is really not an exceptional situation, would it not be better to use the optional parameter for get?
>>> choices = {1:'one', 2:'two'}
>>> print choices.get(n, 'too big!')
>>> n = 1
>>> print choices.get(n, 'too big!')
one
>>> n = 5
>>> print choices.get(n, 'too big!')
too big!
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With