Hi How to implement switch case statement.

parasuram.nooranianand at wipro.com parasuram.nooranianand at wipro.com
Tue Jun 26 02:23:22 EDT 2007


Hi 
 
  My requirement is to check a variable with a set of constant values
and call a particular function depending on the value of the variable. A
C-language  implementation might look something like :
 
switch (a) {
 
    case 1 : func1();
    case 2 : func2() ;
    default : func3();
}
 
How to do it in Python ? 
 
Ofcourse an if-elif construct can also be used to do the job, which is
indeed my last option. However i would like to know if a 'switch-case'
option is available.
 
I found some implementations involving dictionaries and lambdas but i
don't know how suitable they might be for this kind of an
implementation.
 
Any suggestions and ideas welcome
 
 
 
Thanks and regards
Parasuram N.A.
I know the answers to all the questions
But its just that i don't find some of them worth answering
 
 
 
 



The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. 

WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
 
www.wipro.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070626/9b5b6f8f/attachment.html>


More information about the Python-list mailing list