gpt4 book ai didi

python - 如何表示类的实例与获取它作为输入的类之间的关系?

转载 作者:行者123 更新时间:2023-12-03 21:42:07 26 4
gpt4 key购买 nike

我有一个类(class)叫 House .这个类的实例是house .

class House:
def __init__(self, height, length):
self.height = height
self.length = length

def housePlan():
houseHeight = self.height
houseEdgeLength = self.length

house = House(height,length)
我还有一个类(class)叫 Person .此类获得多个输入,包括 House 的实例.
class Person:
def __init__(self,name, house):
self.name = name
self.house = house
问题编辑:我想向观众展示我的节目,我如何用图表展示这些关系?

最佳答案

I have another class called Person. This class gets several inputs including an instance of House


House 的实例不仅在 Person 的构造函数的参数中给出,而且是类的属性( self.house = house ),所以:
enter image description here
我说 name 是一个很有可能的字符串。
所有属性/属性/操作都是公开的,以遵守 Python 规则。
在类图的级别上,不可能看到操作的参数来自哪里,为此您可以使用交互(例如,在下一个问题中我也放了一个序列图 answer )或一个事件
(奇怪的是你的房子有长没有宽,所以必须是正方形)

关于python - 如何表示类的实例与获取它作为输入的类之间的关系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66934927/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com