尤其针对机器人调试的时候,我们希望它能够切换模式进行不同任务,但是python中并没有类似的if define或者switch等操作,
但是可以做一个类似的switch,例如,本人也写了一个多任务执行模板
task = 6 # choose which task to execute
def task1():
print("task 1 completed !")
def task2():
print("task 2 completed !")
def task3():
print("task 3 completed !")
def task4():
print("task 4 completed !")
def task5():
print("task 5 completed !")
def task6()):
print("task 6 completed !")
def default():
print("Invalid Operation!")
switch={
1:task1,
2:task2,
3:task3,
4:task4,
5:task5,
6:task6,
}
switch.get(task,default)()