参考Python Args [英] Python Args By Reference
问题描述
大家好,我想知道是否有办法通过引用(地址)传递参数
(整数等),而不是按值传递。
非常感谢提前。
-Wes
2005年-05-10,ncf< no *************** @ gmail.com>写道:
大家好,我想知道是否有任何方法可以通过引用(地址)而不是值来传递参数
(整数等)。 / blockquote>
是的。所有参数都通过引用传递。这必须在某个地方的常见问题解答中...
果然。浏览常见问题解答30秒就产生了这样的结果:
http://www.python.org/doc/faq/progra...l-by-reference
-
格兰特爱德华兹格兰特哇!哇!看!!在丸子上流浪了
!!让我们采访
visi.com吧!
ncf写道:
大家好,我想知道是否有任何方法可以通过引用(地址)传递参数
(整数等),而不是按值传递。
非常感谢提前。
-Wes
python中的所有可变类型都会自动通过引用传递。
< blockquote> Joseph Garvin写道:ncf写道:
大家好,我想知道是否有任何方法可以传递参数
(整数和通过引用(地址),而不是通过值。
非常感谢提前。
python中的所有可变类型都是通过引用自动传递的。
更准确:
(1)所有函数参数都按值传递,但是
(2)所有值是指针。
声明(2)也解释了为什么
a = [1,2,4]
b = a
b [1] = 0
打印
[1,0,4]
就像它一样。
并且mutable和immutable之间没有区别类型。它是
只是那些不可变的类型,它们如何通过并不重要。
Hello all, I was wondering if there was any way to pass arguments
(integer and such) by reference (address of), rather than by value.
Many thanks in advance.
-Wes
On 2005-05-10, ncf <no***************@gmail.com> wrote:
Hello all, I was wondering if there was any way to pass arguments
(integer and such) by reference (address of), rather than by value.
Yes. All arguments are passed by reference. This must be in
the FAQ somewhere...
Sure enough. 30 seconds of browsing the FAQ yielded this:
http://www.python.org/doc/faq/progra...l-by-reference
--
Grant Edwards grante Yow! Wow! Look!! A stray
at meatball!! Let''s interview
visi.com it!
ncf wrote:
Hello all, I was wondering if there was any way to pass arguments
(integer and such) by reference (address of), rather than by value.
Many thanks in advance.
-Wes
All mutable types in python are passed by reference automatically.
Joseph Garvin wrote:ncf wrote:Hello all, I was wondering if there was any way to pass arguments
(integer and such) by reference (address of), rather than by value.
Many thanks in advance.
All mutable types in python are passed by reference automatically.
More accurately:
(1) All function arguments are passed by value, but
(2) All "values" are pointers.
Statement (2) also explains why
a = [1, 2, 4]
b = a
b[1] = 0
print a
[1, 0, 4]
behaves the way it does.
And there''s no difference between mutable and immutable types. It''s
just that with immutable types, it doesn''t matter how they''re passed.
这篇关于参考Python Args的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!