分类方法;返回给定的输入

时间:2015-12-03 23:47:48

标签: python

我有代码:

class Triangle(Coordinate):
    def __init__(self,xcoord,ycoord,color):
        self.color = color
        super().__init__(xcoord,ycoord)

(从类Coordinate继承) 每当我打电话给它时,例如

t1 = Triangle(Coordinate(1,1), Coordinate(2,1), Red)

它只返回坐标,它如何使它返回颜色?

1 个答案:

答案 0 :(得分:0)

答案已在评论中公布,但我认为你误解了他,所以我将详细说明一下。

你的类Triangle继承了某种父类的函数。即使你没有在Triangle中编写def __str__(self):,它仍然可以使用,因为它是在你的父类中定义的,而Triangle继承了父类的函数

如果您不想使用任何父类'函数,您可以在Triangle中重新定义它。当你在Triangle上调用该函数时,Python会更喜欢在引用父类之前在Triangle中使用def __str__(self):

简而言之,您需要编写一个与父类中的def __str__(self):类似的新<?php $servername = "???"; $username = "???"; $password = "???"; $dbname = "???"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT doctor FROM booking WHERE datereq BETWEEN '2015-11-02 09:00:00' AND '2015-11-02 10:00:00'"; $result = $conn->query($sql); echo " <table width='80%' align='center' > <div id='head_nav'> <tr>"; echo"<th>Time</th> <th>Monday</th> <th>Tuesday</th> <th>Wednesday</th> <th>Thursday</th> <th>Friday</th> </tr> </div>"; echo"<tr><th>09:00 - 10:00</th><td>"; if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo "<br>". $row["doctor"]. "<br>"; echo "<br>". $row["doctor"]. "<br>"; echo "<br>". $row["doctor"]. "<br>"; } } else { echo "0 Results"; } $sql = "SELECT doctor FROM booking WHERE datereq BETWEEN '2015-11-03 10:00:00' AND '2015-11-03 11:00:00'"; $result = $conn->query($sql); echo"<tr><th>10:00 - 11:00</th><td>"; if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo "<br>". $row["doctor"]. "<br>"; echo "<br>". $row["doctor"]. "<br>"; echo "<br>". $row["doctor"]. "<br>"; } } else { echo "0 Results"; } $conn->close(); ?> ,但在输出中添加另一部分来计算颜色。我希望这有助于Charmaine。祝你好运!