我可以在 python 格式功能打印行中使用换行符吗?

Can I use line breaks in a python format funtion print line?

这是我要拆分的代码行,它工作正常,但它是一行很长的代码,如何在这样的格式函数打印行中使用换行符?

return '{0.name} is a {0.sex} rabbit and has {0.fur_colour} fur and {0.eye_colour} eyes, {0.name} is of the {0.breed} breed of rabbits.\n{0.name} is '.format(paul)+ disp_age

您可以将整个拆分后的字符串存储到 ()

return ("{0.name} is a {0.sex} rabbit"
    " and has {0.fur_colour} fur and "
    "{0.eye_colour} eyes, {0.name} is "
    "of the {0.breed} breed of rabbits.\n"
    "{0.name} is ").format(paul)+ disp_age

这个关于多行字符串的回答很有用: