Finishing function ------

Order function parameters

Location parameter> * args> The default value of the parameter> ** kwargs
 
Another kind of parameter passing ⼀ dynamic parameters of shutter mode:  to ⼀ sequence, the argument list of locations, the object can ⾯ previous iteration plus a * table displayed in order to break up this sequence
= L [11,22,33,44 ] 
S = " Chenqie do " 
DEF Fun (* args):
     Print (args)      
Fun ( * L)        # Fun print result is: (11, 22, 33, 44 ) 
Fun (S *)        # Fun print result is: ( 'Hill', 'concubine', 'do', 'no', 'to')
In the parameter table position on the * monitor the composition into ⼀ received parameter tuple
If ⼀ a dictionary , you can also break up. But it needs * Use two
def fun(**kwargs):
    print(kwargs)
dic = {'a':1, 'b':2}
fun(**dic)      #   {'a': 1, 'b': 2}
Function Note:
DEF Chi (food,. Drink.):
 "" " 
individual cases from is a comment function to write to record the next current function is, dry or something, ⽐ as my function is ⼀ to eat 
: param: param food: Parameter food is what it means 
: param: param drink: drink parameter What does it mean 
: return: return: the return of what stuff 
 "" " 
Print (Food, drink)
 return  " Very Good "
Namespaces
After the python interpreter began YES, it will open up more space in memory ⼀, whenever encountered ⼀ variables, put the variable relationship between the name and the value recorded, but when faced with the function definition, interpreter just read into memory function name, table displayed this function existed, ⾄ in variables and internal logic functions, the interpreter is not shut Center Weighted that ⼀ start
When the function is only loaded in, only this ⽽ is only when the function is called and visited, the interpreter will come into the open interior space ⾏ variables based on variables declared within a function. With complete function Perform these Using the function of the internal variables accounted for as a function of the space will be cleared perform complete ⽽
Namespace Category:
1. global namespace -> py us directly in the file, the variable declared outside the function belong to the global namespace
2. Local namespace -> variables declared in a function will be kept in the local namespace
3. Built-in namespace -> storage python interpreter provides us with the name, list, tuple, str, int these are built namespaces
Load order:
1. Built-in namespace
2. global namespace
3. Local namespace (function is to perform to time)
The value of the order:
1. local namespace
2. global namespace
3. Built-in namespace
We can see by the global globals () function for content Use domain, can also be viewed locally as by locals ()
Using variables and functions in the domain of information
print(globals())    #{'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x00466590>, '__spec__': None, 
            '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, '__file__': 'C:/Users/ZYP/PycharmProjects/python_ui/test_tools/test.py', '__cached__': None}
def func(): a = 10 print(locals()) #{'a': 10} func()
For variable data types directly into ⾏ access, but can not change the address, said the white. Can not be assigned
l = [11,22,33,44]
def fun():
    l.append(55)
    print(l)    #      [11, 22, 33, 44, 55]
fun()
print(l)         #      [11, 22, 33, 44, 55]

 

Guess you like

Origin www.cnblogs.com/Aline2/p/11262557.html