Today's learning Record:
Functions, variables
Examples of functions:
#函数返回def test1 (): Print ("in the Test1") return 0#return is empty, when not written, this function is a procedure, the default return is empty, that is, none; #return为一个对象时, return this object directly, such as 0, return 0 ; #retrun为很多对象时, such as the three-dimensional and list, dictionaries, etc., will form a tuple to return
#函数变量示例:
#变量def test1 (x, Y, z) print print (y) print (z) test1 (All-in-one) #其中, with a real argument, x, Y, z as a parameter, and a position variable, each of which corresponds to the Test1 (x=1,y=2,z=3) #其中, the variable is a keyword variable, and the position can be arbitrarily changed, such as Y=1, X=2,z=3test1 (1,2,z=3) #可以这么写, the keyword variable must be located after the position variable test1 (1,y=2,3) #不可以这么写, for reasons such as the # Default variable def test1 (x,y=2,z) print (x) print (y) print (z) test1 (1,3) #其中, x=1,y=2,z= 3,y default is 2, can not pass in variable parameter test1 (1,5,3) #其中, x=1,y=5,z=3,y passed variable is 5, mainly applies in the default value, default installation, default port, etc. # variable group def test1 (X,y=2,*args) print (x) print (y) print (*args) test1 ( 1,2,3,4,5,6) #4, 5,6 as a tuple to args, generally do not know how many variables to use, or as an extension or test1 (1,2,*[4,5,6]) def test1 (X,y=2,*args,**kwargs) print (x) print (y) print (args) print (Kwargs) test1 (1,2,3,4,5,6,name= "Alex", sex= "M", age=8) #4, 5,6 passed to args as a tuple, Generally do not know how many variables to use, name,sex,age, etc. as a dictionary passed to the variable, orUsed as an extension or test1 (1,2,*[4,5,6],**{"name": "Alex", "Sex": "M", "Age": 8}) The above variable forms can be combined, and finally it must be noted that The keyword variable cannot be written after the position variable.
Python Learning record-2016-01-19