为什么这会返回国家代码?
from pygal.maps.world import COUNTRIES
def get_country_code(country_name):
"""Return the Pygal 2-digit country code for the given country."""
for code, name in COUNTRIES.items():
if name == country_name:
return code
return None
print(get_country_code('Andorra'))
print(get_country_code('United Arab Emirates')
为什么这不返回国家代码?
from pygal.maps.world import COUNTRIES
def get_country_code(country_name):
"""Return the Pygal 2-digit country code for the given country."""
for code, name in COUNTRIES.items():
if name == country_name:
return code
return None
print(get_country_code('Andorra'))
print(get_country_code('United Arab Emirates')
主要区别在于我如何缩进'return None'。即使我放了 else 语句,它也不会返回代码。有人可以向我解释一下吗?我是编程新手。