我在试一些函数,运行它时什么也没有
def formatted_city(city_name, country_name): formatted_name = city_name + "' " + country_name return formatted_name.title() formatted_city('cairo', 'egypt')
预期:“开罗‘埃及”
实际结果:什么都没有发生
当我测试它的时候它也没有给我任何东西
这取决于控制台。如果你在google collab中运行这个(我做过),它将打印出这两个城市。但是,在大多数gui中,您不应该期望打印任何内容,因为格式化的\u name.title()没有保存到任何变量。你可以的
x = formatted_city('cairo', 'egypt') print(x)
会打印出你想要的
你需要 print 它:
print
print(formatted_city('cairo', 'egypt'))
输出:
Cairo' Egypt