Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
什么';Python中对象的属性和方法之间的链接是什么?_Python_Methods_Attributes - Fatal编程技术网

什么';Python中对象的属性和方法之间的链接是什么?

什么';Python中对象的属性和方法之间的链接是什么?,python,methods,attributes,Python,Methods,Attributes,我是Python新手,我指的是它们实现方式的不同 例如: >>> a=np.array([1,2,5,3,43]) >>> a.sort() >>> a array([ 1, 2, 3, 5, 43]) >>> a=np.array([1,2,5,3,43]) >>> a.shape (5,) >>> a.sort() >>> a array([ 1, 2, 3

我是Python新手,我指的是它们实现方式的不同

例如:

>>> a=np.array([1,2,5,3,43])
>>> a.sort()
>>> a
array([ 1,  2,  3,  5, 43])
>>> a=np.array([1,2,5,3,43])
>>> a.shape
(5,)
>>> a.sort()
>>> a
array([ 1,  2,  3,  5, 43])
>>> a.sort
<built-in method sort of numpy.ndarray object at 0x7f78e358a9e0>
>>> a.shape()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'tuple' object is not callable
>a=np.数组([1,2,5,3,43])
>>>a.排序()
>>>a
数组([1,2,3,5,43])
>>>a=np.数组([1,2,5,3,43])
>>>a.形状
(5,)
>>>a.排序()
>>>a
数组([1,2,3,5,43])
>>>排序
>>>a.形状()
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
TypeError:“tuple”对象不可调用

也许答案应该是类似于在Python中特殊使用“\ufoo\ufoo”的方法是与对象关联的函数。键入a.sort时,它将返回存储函数的内存中的地址,如果使用括号,它将调用函数。属性只是对象中的一个变量,因此当您调用.shape()时,它会给您一个错误,因为您试图将变量作为函数调用


不确定这是否是您想要的,但我希望它有所帮助

属性就是值。方法是一个“函数”。@DYZ我的意思是它们之间有什么联系?我听说了一些关于“foo”的事,关于“foo”的事吗?没有链接。它们是不相关的,只是它们都属于同一个对象。