python:*args、**kwargs和assert

. 1  "" " 
2      * args and kwargs **
 . 3      * args: encapsulating the parameter to the function using the tuple
 . 4      ** kwargs: dic parameter to the function package to use
 . 5  " "" 
. 6  
. 7  DEF function1 (A, * args) :
 . 8      Print (A, args)
 . 9 function1 (. 1, 2,. 3,. 4 )
 10  
. 11  DEF function2 (A, ** kwargs):
 12 is      Print (A, kwargs)
 13 is function2 (. 1, B = 2, C =. 3 )
 14  
15  DEF Function3 (A, B):
 16      Print (A)
 . 17      Print (B)
 18 isFunction3 (* (1, 2))   # tuple (1, 2) to an 1, 2 
. 19 Function3 (** { ' A ' : ' Hello ' , ' B ' : ' World ' })   # The dictionary { 'a': 'hello', 'b': 'word'} resolves to a = 'hello', b = 'world'
1 (2, 3, 4)
1 {'b': 2, 'c': 3}
1
2
hello
world
. 1  "" " 
2      Assert: throwing an exception condition is not satisfied
 . 3  " "" 
. 4  Assert . 1 ==. 1
 . 5  Assert . 1 == 2, ' . 1 is not equal to 2 '
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-22-cb69595573b9> in <module>
      3 """
      4 assert 1 == 1
----> 5 assert 1 == 2, '1 is not equal to 2'

AssertionError: 1 is not equal to 2

 

Guess you like

Origin www.cnblogs.com/techi/p/11628403.html