class Slot:
# the '__init__' method is the constructor
# the first argument must be 'self' (as with any method belonging to the class)
#the advantage of giving default values (here 'None') is that you do not have to care the parameter order when calling the method
def __init__(self,SerialNumber=None,PartNumber=None,
Name=None,Status=None,Type=None):
self.SerialNumber = SerialNumber
self.PartNumber = PartNumber
self.Name = Name
self.Status = Status
self.Type = Type
print('Name: ',Name,' ; SerialNumber: ',SerialNumber,
' ; PartNumber: ',PartNumber,
' ; Status: ',Status,' ; Type: ',Type)
# further in the code, you create the instances of the object Slot
CPM = Slot(Name='CPM', PartNumber='toto', Type='poo')# just to show you can give any parameter in any order
IOM = Slot(Name='IOM')
MDA = Slot(Name='MDA')
# to access the values of instances:
print('CPM name: ',CPM.Name)
print('CPM Type: ', CPM.Type)
CPM.Type = 'paa'
#...
你的问题似乎很基本。你可以很容易地找到信息。。。 听起来你只是想找个人为你工作。你知道吗
但这次让我们给它一点时间。 如果我知道你想要3个“槽”结构的实例。就这样? 一种可能性是:
下面的示例应该按照您的要求执行。在我看来,让类初始值设定项打印出信息是不明智的,因此在main函数中执行手动打印。改变这一点将是微不足道的,但作为一个练习留给读者。你知道吗
这应该做到:
相关问题 更多 >
编程相关推荐