(5) Function 2

quote
What is a reference: a variable reads data through the memory starting address of the data
a = 1 : indicates that the variable a points to the memory starting address of 1
In python, values ​​are passed by reference. We can use id( ) to determine whether two variables are references to the same value. We can understand the id value as the address of that piece of memory.
 
Variable type:
    Variable type: modify the variable data, the address referenced by the variable has not changed         (list, dictionary, set)
    Immutable types: if the content is modified, the address of the variable's reference changes      (number, string, tuple, boolean)  
     {Once reassigned, the memory address must change}
Immutable type data is passed as an actual parameter, modifying the formal parameter has no effect on the actual parameter
Variable type data is passed as an actual parameter, and if the formal parameter is modified, the actual parameter will change accordingly; if the formal parameter is reassigned and the formal parameter is modified, the actual parameter will not be affected.
  • Function parameters in Python are passed by reference (note that it is not passed by value)
Note: In the list: += and =+ are special columns
    += : will add data to the end of the original list
    =+: a new list is generated

 

{ Extension: Hash algorithm: A number can be calculated from a data, the hash value of the same data must be the same}
 
recursive function:
    It is a cycle itself, generally not used
    There must be an end condition, otherwise it will fall into an infinite loop
 
Anonymous function:
     Use the lambda keyword to create small anonymous functions (without function name definitions) 
      The syntax of a lambda function consists of only one statement: lambda+expression
#Format : lambda arg1, arg2: arg1 + arg2 arg1, arg2: formal parameter arg1 + arg2: operation expression 
sum = lambda arg1, arg2: arg1 + arg2
 # call the sum function 
print ( " Value of total : " % sum( 10 , 20 ))
 print ( " Value of total : " % sum( 20, 20 ))
Lambda functions can take any number of parameters but can only return the value of one expression
An anonymous function cannot call print directly, because the lambda requires an expression
Anonymous functions can be passed as parameters
 
Attachment: Dictionary sorting: variable name.sort (key=anonymous function)
 
List comprehension:
    ps: lightweight loop to create list
>>a = [x for x in range(4)]  
>> [0,1,2,3]
# Multiple for loops, multiple variables to receive
 
Collection (set):
    Set: curly brackets, unordered, no duplicate data, cannot be obtained by subscript
                (only add and delete)
    Function: perform deduplication conversion type (there cannot be a list in the collection)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325163232&siteId=291194637