按价值或参考? [英] By value or by reference?

查看:54
本文介绍了按价值或参考?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!


Python如何将函数传递给函数?通过价值或参考?


谢谢,

Riccardo Rossi。

解决方案

< blockquote> Riccardo Rossi写道:

大家好!

Python如何将参数传递给函数?通过价值或参考?

谢谢,
Riccardo Rossi。



参考一个物体....见python tutorial。


" Riccardo Rossi" < RI *************** @ email.it>写道:

大家好!

Python如何将参数传递给函数?按价值或参考?




IIRC,参考。它使用写入算法的副本。


-

Godoy。 < go *** @ ieee.org>


Roger Irwin写道:

Riccardo Rossi写道:

大家好!

Python如何将函数传递给函数?按价值还是按
参考?


谢谢,
Riccardo Rossi。

通过引用一个对象....参见python教程。




错误。以下是传递参考和传递

值到CS类型之间的区别:

def foo(a):a = 1
。 ... i = 10
foo(i)
print i




带参考传递,我现在是1.但是,由于python是价值传递的价值,它仍然是10.


-Jonathan


Hi all!

How does Python pass arguments to a function? By value or by reference?

Thanks,
Riccardo Rossi.

解决方案

Riccardo Rossi wrote:

Hi all!

How does Python pass arguments to a function? By value or by reference?

Thanks,
Riccardo Rossi.


By reference to an object....See the python tutorial.


"Riccardo Rossi" <ri***************@email.it> writes:

Hi all!

How does Python pass arguments to a function? By value or by reference?



IIRC, by reference. It uses a copy on write algorithm.

--
Godoy. <go***@ieee.org>


Roger Irwin wrote:

Riccardo Rossi wrote:

Hi all!

How does Python pass arguments to a function? By value or by reference?


Thanks,
Riccardo Rossi.


By reference to an object....See the python tutorial.



Wrong. Here is the difference between pass by reference and pass by
value to CS types:

def foo(a): a = 1 .... i = 10
foo(i)
print i



With pass-by-reference, i would now be 1. However, since python is
pass-by-value, it remains 10.

-Jonathan


这篇关于按价值或参考?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆