One, the value of the tuple:
In general, the function pass parameter is 1 to 1, here X, Y is 2 parameters, according to the reason to pass 2 parameters, if the direct transfer of the ancestor, is actually passed a parameter
def Show (x, y): ... Print >>> a = (ten )>>> Show (A, 20) 100
And if you want to pass a meta-ancestor (2 items) to X and Y, pass the time to use *a, if a function to 3 parameters, you can not pass 2 Ganso
def Show (x, y): ... Print " %s:%s " %>>> a= (10,20)>>> Show (*a)10:20>>> b= (10,20,30 )>>> Show (*b) Traceback (most recent): "<stdin> " in <module>2 arguments (3 given)
Print "%s:%s"% (x, y)
This percent%s is similar to the C-language printf, where the placeholder represents a string to interpret, and the trailing% (x, y) is the value of the pass. X passed to the first%s, Y to the second%s
If the value is not passed later, the string itself is printed
Print " %s:%s " ' Hello ' ' GHOSTWU ' ) HELLO:GHOSTWUprint"%s:%s"%s:%s
Second, the variable scope is the same as JavaScript
The outside of the function defines a global variable that can be accessed inside or outside the function
The function defines a local variable, which is released after the function call is complete.
>>> myname ='GHOSTWU'>>>defShow (): ...Printmyname ... x= 10... >>>Show () Ghostwu>>>Xtraceback (most recent): File"<stdin>", Line 1,inch<module>Nameerror:name'x' is notdefined>>>myname'GHOSTWU'>>>
The Global keyword can change a local variable to a global variable, which is not the same as PHP (PHP refers to a global variable that is used inside a function)
def Show (): ... Global a ... .. = Ten>>> Show ()>>> a10
Global variables and local variables with the same name, local variables are accessed inside the function, global variables are outside
def Show (): ... = Ten ... Print >>> a100>>> show ()10>>> a100
If the local variable with the same name is global and the function is executed, then the function executes after the output of the variable, which is the value in the local variable.
def Show (): ... Global a ... .. = 2>>> a1>>> show ()>>> a2
Python variable scope, function and parameter