我需要复制一个变量并对其进行更改。我已经看过了,但我想要这个网站。在这段代码中,我需要返回的元组是两个不同的列表,而不是相同的。
def getIPRange(self):
group = [0, self.getJoinedNetworks() - 1]
while True:
if self.ip[2] > group[0] and self.ip[2] < group[1]:
res_ip_min = self.ip #self.ip is for example [70, 30, 20, 0]
res_ip_min[2] = group[0]
res_ip_min[3] = 1
res_ip_max = self.ip
res_ip_max[2] = group[1]
res_ip_max[3] = 254
return (res_ip_min, res_ip_max)
else:
group[0] = group[1] + 1
group[1] = group[0] + self.getJoinedNetworks() - 1
最常见的可能是进行
...
res_ip_min = list(self.ip)
...
res_ip_max = list(self.ip)
...
它从self.ip的元素创建了一个新的列表。或者,您可以使用python的复制实用程序