is the parameter pass of Python a value pass or a reference pass??

Source: Internet
Author: User

function parameter passing mechanism, what does the value and the reference mean?

The problem of function parameter passing mechanism is essentially the method that calls the function (procedure) and the called function (procedure) to communicate when the call occurs. There are two basic parameter passing mechanisms: value passing and reference passing.

In the process of value passing (passl-by-value), the formal parameters of the called function are treated as local variables of the called function, that is, the memory space is opened up in the stack to hold the values of the arguments put in by the main key function, so as to become a copy of the arguments. The characteristic of value passing is that any operation of the tuned function on the situation parameter is performed as a local variable and does not affect the value of the argument variable of the main key function.

In the reference Pass (pass-by-reference) process, the formal parameters of the called function, while also opening up the memory space in the stack as a local variable, are stored in the address of the argument variable that is put in by the main key function. Any operation of the modulated function on the formal parameter is handled as an indirection, that is, the argument variable in the keynote function is accessed through the address stored in the stack. Because of this, any manipulation of the modulated function on the parameter affects the argument variables in the keynote function.

In Python, you can have multiple references pointing to one memory at a time.

Python does not allow programmers to choose whether to use a value or to pass a reference. Python parameter passing is definitely a way to "pass an object reference". This approach is equivalent to a synthesis of the value of the pass and the reference. If a function receives a reference to a Mutable object (a dictionary, a list), it can modify the original value of the object-the equivalent of a ' pass-reference ' to pass the object. If a function receives a reference to an immutable object (a number, a character, or a tuple), it cannot directly modify the original object-equivalent to passing the object through ' value passing '.

is the parameter pass of Python a value pass or a reference pass??

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.