A dictionary-based 'switch' : Switch : Statement PYTHON TUTORIALS


PYTHON TUTORIALS » Statement » Switch »

 

A dictionary-based 'switch'


choice = 'ham
print {'spam':  1.25,           # A dictionary-based 'switch'
       'ham':   1.99,           # Use has_key or get for default
       'eggs':  0.99
       'bacon': 1.10}[choice]



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Statement
» Switch