[英]Passing a list of arguments into a class
I am creating a class called Triangle
.我正在创建一个名为Triangle
的类。 Within Triangle
, it is passed three_points
list and two_angles
list (ie self.triangle0 = Triangle([1, 2, 3], [20, 30])
)在Triangle
,它传递了three_points
列表和two_angles
列表(即self.triangle0 = Triangle([1, 2, 3], [20, 30])
)
I am defining我正在定义
class Triangle(object):
def __init__(self, three_points, two_angles):
self.points = three_points
self.angles = two_angles
Since it is a list I am passing in and not just a single number, do I have to create lists to put the values in or does this just work?由于它是我传入的列表,而不仅仅是一个数字,我是否必须创建列表来放入值,或者这是否有效?
This will work how you have it mocked up.这将如何模拟它。 At runtime self.points will be a list containing whatever values you passed in. Same with self.angels.在运行时 self.points 将是一个包含您传入的任何值的列表。与 self.angels 相同。 Note that if your list contains objects and not just primitives you may be passing in a pointer in your list and not the actual object.请注意,如果您的列表包含对象而不仅仅是基元,您可能会在列表中传递一个指针而不是实际对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.