gpt4 book ai didi

python - 我可以在 python 格式函数打印行中使用换行符吗?

转载 作者:行者123 更新时间:2023-12-02 09:17:53 24 4
gpt4 key购买 nike

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

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

这个关于多行字符串的答案很有用: https://stackoverflow.com/a/10660443/7042357

关于python - 我可以在 python 格式函数打印行中使用换行符吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59826482/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com