python 指针数组_向python类传递指针数组

Python没有指针。或者说,Python中的所有东西都是指针,包括名称、列表中的条目、属性。。。Python是一种“通过引用传递”的语言。在

下面是几个简单的例子:In [1]: a = ['hello', tuple()] # create a new list, containing references to

# a new string and a new tuple. The name a is

# now a reference to that list.

In [2]: x = a # the name x is a reference to the same list as a.

# Not a copy, as it would be in a pass-by-value language

In [3]: a.append(4) # append the int 4 to the list referenced by a

In [4]: print x

['hello', (), 4] # x references the same object

In [5]: def f1(seq): # accept a reference to a sequence

...: return seq.pop() # this has a side effect:

# an element of the argument is removed.

In [6]: print f1(a) # this removes and returns the last element of

4 # the list that a references

In [7]: print x # x has changed, because it is a reference to the same object

['hello', ()]

In [8]: print id(a), id(x)

4433798856 4433798856 # the same

In [9]: x is a # are x and a references to the same object?

Out[9]: True

Python提供了高级构造来完成在C语言中需要使用指针算法的操作,因此您不必担心给定变量是否是指针,就像您不必担心内存管理一样。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值