Sunday, February 8, 2015

Switch Case in Python

Problem:

This is for my understanding and memory I  need to write about the Python way of writing switch case. One such way is writing the if elif and else construct but the other way as mentioned in the some of the code I have seen as is to use the dictionary as key value pair and match the key of the dictionary key as a case value and return the same from the dictionary.

Solution:

The solution below explains the logic for the same and do keep in mind why this is working out because

  • For the dictionary a = {key:value}  the expression a[key]  and {key:value}[key] are same and will give out value

1 comment:

  1. I really appreciate the information shared above. It’s of great help. If someone wants to learn Online (Virtual) instructor lead live training in #APACHE#CAMEL, kindly contact us http://www.maxmunus.com/contact
    MaxMunus Offer World Class Virtual Instructor-led training on #APACHE #CAMEL. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ pieces of training in India, USA, UK, Australia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain, and UAE etc.
    Avishek Priyadarshi
    MaxMunus
    E-mail: avishek@maxmunus.com
    Skype id: avishek_2.
    Ph:(0) 8553177744 / 080 - 41103383
    http://www.maxmunus.com/

    ReplyDelete