\'Hello \' + (\'there\' if name is None else name)
Is the equivalent of
msg = \'Hello \'
if name is None:
msg += \'there\'
else:
Firstly, run 'pip install pyswitch'
Then:
import pyswitch
mySwitch = pyswitch.Switch()
@mySwitch.case(None):
def gotNone(value):
return 'Hello there'
@mySwitch.case('Mr. Anderson')
def gotMrAnderson(value):
return 'Hello Neo'
@mySwitch.default
def gotDefault(value):
return 'Hello %s' % value
msg = mySwitch.switch(None) # Returns 'Hello there'
msg = mySwitch.switch('Mr. Anderson') # Returns 'Hello Neo'
msg = mySwitch.switch('OoglyMoogly') # Returns 'Hello OoglyMoogly'