1.三目运算符 对简单的条件语句,可以用三元运算简写.三元运算只能写在一行代码里面 # 书写格式 result = 值1 if 条件 else 值2 # 如果条件成立,那么将 "值1" 赋值给result变量,否则,将"值2"赋值给result变量 result = 'the result if the if succeeds' if True else 'the result if the if fails and falls to the else part'…
1. 可变长参数 在函数中可变长参数分为两种:一种是非关键字参数,表示为元组:一种是关键字参数,表示为字典. 具体看下面的例子代码,相当于单元测试: #!/usr/bin/env python #'this is a example of the unit test' def testit(func,*nkwargs,**kwargs): 'this is the test of the function' try: retval = func(*nkwargs,**kwargs) #调用函数来…