pass function value by reference

def test1(b): # The variable b must be a local variable, depending on who it points to? mutable or immutable
    b += b # += is to directly modify the space pointed to by b, instead of letting b point to a new one
    # b = b+b # xx = xx+yyy First calculate the result on the right side of the = sign, and then let b point to this new place, no matter who the original b points to
               # Now b must point to this new place

# a = [11, 22]
a = 100
test1(a)
print(a)
# Function parameters in Python are passed by reference (note that it is not passed by value)
# For immutable types, the dependent variable cannot be modified, so the operation does not affect the variable itself
# For variable types, the operation in the function body may change the incoming parameter variable

  

Guess you like

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