我有一個關於python 2.7和def函數的問題,因爲有關於綁定方法的問題。這是從學校分配:dpython綁定方法錯誤
下面的代碼:
從ABC進口ABCMeta,abstractmethod 進口數學
class Shapes(object):
__metaclass__= ABCMeta
@abstractmethod
def __init__(self):
pass
class TwoDShapes(Shapes):
def __init__(self):
pass
class ThreeDShapes(Shapes):
def __init__(self):
pass
================= Main.py =====================
from BasicClassShapes import*
class Rectangle(TwoDShapes):
def __init__(self, nameOfShape, length, width, numberofSides, numberOfVertices):
self.nameOfShape = "Rectangle"
self.length = length
self.width = width
self.numberofSides = 4
self.numberOfVertices = 4
super(Rectangle,self).__init__()
def perimeter(self):
self.perimeter = length*2 + width*2
def Area(self):
self.Area = length*width
====================================
def PrintALL():
A = Rectangle("Rectangle", "10", "20", "4", "4")
print "This is the name of the shape: ", A.nameOfShape
print "This is the length: ", A.length
print "This is the width: ", A.width
print "This is the number of side: ", A.numberofSides
print "This is the number of vertice: ", A.numberOfVertices
print "This is the perimeter: ", A.perimeter
print "This is the area: ", A.Area
print "\n"
PrintALL()
=============== Result =======================
This is the name of the shape: Rectangle
This is the length: 10
This is the width: 20
This is the number of side: 4
This is the number of vertice: 4
This is the perimeter: <bound method Rectangle.perimeter of <__main__.Rectangle object at 0x03BEFC90>>
This is the area: `<bound method Rectangle.Area of <__main__.Rectangle object at 0x03BEFC90>>`
抱歉,這是我第一次使用本網站= = – LDs
可憐的間距怎麼我不知道做什麼用的標籤的事情做 – LDs
不用擔心,點擊下面您的文章「編輯」和適當的格式化代碼使用'{}'按鈕。有預覽會告訴你它是否有效 – chrki