<p>我对python非常陌生,正在寻找简化以下内容的方法:</p>
<pre><code>if atotal == ainitial:
print: "The population of A has not changed"
if btotal == binitial:
print: "The population of B has not changed"
if ctotal == cinitial:
print: "The population of C has not changed"
if dtotal == dinitial:
print: "The population of D has not changed"
</code></pre>
<p>很明显,_total和_initial是预定义的。
提前谢谢你的帮助。在</p>
<p>您可以将所有对组织到字典中,并循环使用所有元素:</p>
<pre><code> populations = { 'a':[10,80], 'b':[10,56], 'c':[90,90] }
for i in populations:
if populations[i][1] == populations[i][0]:
print(i + '\'s population has not changed')
</code></pre>