我是一个刚接触Python的新手,正在寻找一种简化以下代码的方法:
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"
显然,_total和_initial是预定义的。 非常感谢您的帮助。
if
语句的末尾加上冒号。这是一个需要快速内化的好习惯。 - FarmerGedden