擅长:python、mysql、java
<p>正如Marlon所说,您在每次迭代中都将<code>vlan</code>变量重新定义为一个新的dict。在他的答案的基础上,你也可以使用dict理解(如果前一行print语句不是必需的)。你知道吗</p>
<pre><code>vlan = {i: {'name': input("Name: "),
'vlan_id': input("ID: "),
'ip': input("IP: ")} for i in range(num_of_vlans)}
</code></pre>
<p>另外值得注意的是,在构建dict时,两个额外的尾随逗号是不必要的/多余的。你知道吗</p>