Существуют некоторые экземпляры, где я оставлю предупреждения в коде, или где невозможно очистить их (хотя я действительно удаляю тех, я могу). Например:
Так или иначе, те - экземпляры первое, что пришло на ум, где отъезд предупреждений мог бы быть соответствующим.
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:
if x == 1:
pass
elif x == 5:
pass
elif x == 10:
pass
(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.
Try this instead:
def on_function(*args, **kwargs):
# do something
def off_function(*args, **kwargs):
# do something
function_dict = { '0' : off_function, '1' : on_function }
for ch in binary_string:
function_dict[ch]()
Or you could use a list comprehension or generator expression if your functions return values:
result_list = [function_dict[ch]() for ch in binary_string]