Detailed explanation of function passing by value and reference in python

高洛峰
Release: 2017-03-10 18:43:26
Original
1402 people have browsed it

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)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template