python学习笔记:(八)条件语句
if语句,python中if语句的一般形式如下:
conditon1为真,执行statement_block_1
condition1为假,判断conition_2,如果condition_2为真,执行statement_block_2
condition2为假,直接执行statement_block_3
注意:
1、每个条件后,需要使用冒号,标识接下来是满足条件后执行的语句块;
2、使用缩进来划分语句块,相同缩进数的语句在一起组成一个语句块;
3、在python中没有switch--case语句。
如:
1 if bool==1: 2 resultstr = (caseapiname, name, wish,"result值:"+str(bool),"成功") 3 resultmode(','.join(resultstr) + "\n") 4 elif bool=="0": 5 testresult = result.get("error") 6 if testresult==wishresult[col]: 7 resultstr = (caseapiname, name, wish, testresult,"成功") 8 resultmode(','.join(resultstr) + "\n") 9 else: 10 resultstr = (caseapiname, name, wish, testresult,"失败") 11 resultmode(','.join(resultstr) + "\n") 12 else: 13 resultstr =(caseapiname, name, wish,result.get("error"),"失败") 14 resultmode(','.join(resultstr)+"\n")