这可能看起来像一个非常微不足道的问题,但我刚开始学习python类和对象。我有一个像下面的代码。Python - 类和对象
class Point(object):
def __init__(self,x,y):
self.x = float(x)
self.y = float(y)
def __str__(self):
return '('+str(self.x)+','+str(self.y)+')'
def main():
p1 = Point(pt1,pt2)
p2 = Point(pt3,pt4)
p3 = Point(pt5,pt6)
p4 = Point(pt7,pt8)
parray = [p1,p2,p3,p4]
print " Points are", p1,p2,p3,p4
print "parray",parray
我米得到以下输出:
点是(4.0,2.0)(4.0,8.0)(4.0,-1.0)(100.0,1.0) 粒子阵列 - 在0x7ff09f00a550 intersection.Point对象,intersect.Point对象在0x7ff09f00a410,intersection.Point对象在0x7ff09f00a590
我的问题是为什么在打印对象时获取值时,将对象的地址分配给数组? 有人可以建议一种方法来获取由main函数中的数组返回的值吗?
非常感谢你解释得非常好! – buddingengineer
很高兴帮助。我编辑修复了一些拼写错误,而当我处于这种状态时,最终又添加了一些更新,甚至还有一些示例代码,因此请确保查看最新版本。 – Blckknght