Home  >  Article  >  Backend Development  >  Detailed explanation of function passing by value and reference in python

Detailed explanation of function passing by value and reference in python

高洛峰
高洛峰Original
2017-03-10 18:43:261384browse

In python, functions such as integers, strings, and tuples are all passed by value. Their values ​​will not be changed in the function. Others will change their values ​​in the function.

For example, passing a list:

#-*-ecoding:UTF-8 -*-
def fun(a):
    a[0]="sss";
    print a
    print id(a)
    return ;
a=["a","b"];
fun(a);
print a;
print id(a)

Detailed explanation of function passing by value and reference in python

The value in the list has changed, but the address of the list has not changed

The above is the detailed content of Detailed explanation of function passing by value and reference in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn