如何将此代码打印为一行?:
print("If a hippo ways 2000 pounds, gives birth to a 100 pound calf and
then eats a 50 pound meal how much does she weigh?")
我这样做是为了让它更具可读性,我知道我可以使用三引号使其完全按照它的方式打印,并且我可以使用逗号将语句分成两行,但这会使两个单独的字符串(我认为)。有没有办法将语句保持为一个字符串,并将其打印为一行?
答案 0 :(得分:13)
隐式连接相邻的字符串文字:
print("If a hippo ways 2000 pounds, gives birth to a 100 pound calf and "
"then eats a 50 pound meal how much does she weigh?")
答案 1 :(得分:1)
print("If a hippo ways 2000 pounds, gives birth to a 100 pound calf and "\
+"then eats a 50 pound meal how much does she weigh?")