1
我是Python新手,我的意思是它們如何實現的區別。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
也許答案應該是像在Python
屬性是一個值。一種方法是一個「功能」。 – DyZ
@DYZ我的意思是他們之間有什麼**鏈接**?我聽說過_ _ foo _ _,關於「__」的任何事情? – Statham
沒有鏈接。他們是無關的,除了兩者屬於同一個對象。 – DyZ