没有传递值调用? [英] no pass-values calling?

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

问题描述

你好,


我在核心Python编程书中看到了这个陈述,


函数调用的所有参数都是通过引用来形成的,意思是那个

函数中这些参数的任何变化

会影响调用函数中的原始对象。

这是否意味着没有传递 - 调用

python函数的值?只传递参考呼叫?谢谢!

解决方案

2008年1月16日星期三11:09:09 +0800,J。Peng写道:


你好,


我在Core Python Programming书中看到了这个声明,


函数调用的所有参数都是通过引用制作,意味着函数中任何

更改这些参数会影响调用函数中的原始

对象。


这是否意味着在python中没有调用函数的pass-values?

只传递引用调用?谢谢!



不,Python不使用引用传递或传递值。它

使用按对象传递。 (有时称为通过对象引用传递。)


请参阅: http://effbot.org/zone/call-by-object.htm


了解更多详情。

-

史蒂文


Dennis Lee Bieber写道:


因为所有变量都是Python中的名称是对象的引用,

使用名称访问的任何内容都通过引用访问。



任何使用术语变量,引用或按值调用的人都可能以错误的方式解释Python。


对不起老兄:)


Christian


2008年1月16日1 :下午45点,Dennis Lee Bieber< wl ***** @ ix.netcom.comwrote:


On Wed,2008年1月16日11:09:09 + 0800,J。彭" < pe ****** @ gmail.com>


alist = []

anint = 2

astr =触摸我


dummy(alist,anint,astr)


" dummy"只能修改第一个参数的内容 -

整数和字符串不能变异。






如何修改传递给函数的数组?我试过这样的事情:


>> a



[1,2,3]


>> def mytest(x):



.... x = [4,5 ,6]

....


>> ; mytest(a)
a



[1,2,3]


如你所见,a未被修改。

谢谢!


Hello,

I saw this statement in Core Python Programming book,

All arguments of function calls are made by reference, meaning that
any changes to these parameters within the function
affect the original objects in the calling function.
Does this mean there is not pass-values calling to a function in
python? only pass-reference calling? Thanks!

解决方案

On Wed, 16 Jan 2008 11:09:09 +0800, J. Peng wrote:

Hello,

I saw this statement in Core Python Programming book,

All arguments of function calls are made by reference, meaning that any
changes to these parameters within the function affect the original
objects in the calling function.
Does this mean there is not pass-values calling to a function in python?
only pass-reference calling? Thanks!

No, Python does not use either pass by reference or pass by value. It
uses pass by object. (Sometimes called "pass by object reference".)

See: http://effbot.org/zone/call-by-object.htm

for further details.
--
Steven


Dennis Lee Bieber wrote:

Since all "variable" names in Python are references to objects,
anything accessed using a name is accessed by reference.

Anybody using the terms variable, reference or call-by-value is most
likely explaining Python the wrong way.

Sorry dude :)

Christian


On Jan 16, 2008 1:45 PM, Dennis Lee Bieber <wl*****@ix.netcom.comwrote:

On Wed, 16 Jan 2008 11:09:09 +0800, "J. Peng" <pe******@gmail.com>

alist = []
anint = 2
astr = "Touch me"

dummy(alist, anint, astr)

"dummy" can only modify the contents of the first argument -- the
integer and string can not be mutated.

Hi,

How to modify the array passed to the function? I tried something like this:

>>a

[1, 2, 3]

>>def mytest(x):

.... x=[4,5,6]
....

>>mytest(a)
a

[1, 2, 3]

As you see, a was not modified.
Thanks!


这篇关于没有传递值调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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