I am trying to check each index in an 8 digit binary string. If it is '0' then it is 'OFF' otherwise it is 'ON'.
Is there a more concise way to write this code with a switch-like feature?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, it doesn’t. When it comes to the language itself, one of the core Python principles is to only have one way to do something. The switch is redundant to:
(without the fall-through, of course).
The switch was originally introduced as a compiler optimization for C. Modern compilers no longer need these hints to optimize this sort of logic statement.