gpt4 book ai didi

python - 如何漂亮地打印 f 字符串?

转载 作者:行者123 更新时间:2023-12-04 13:10:36 25 4
gpt4 key购买 nike

尝试从 f-String 打印字典:

import pprint as pp

my_dict = {
"key_a": ["here", "are", "the", "things"]
, "key_b": ["that", "i", "want"]
, "key_b": ["to", "share", "with", "the", "worlddddddddddddddddddddd"]
}

pp.pprint(f"Let's talk about all of these things:\n\n{my_dict}")
输出(不漂亮):
("Let's talk about all of these things:\n"
'\n'
"{'key_a': ['here', 'are', 'the', 'things'], 'key_b': ['to', 'share', 'with', "
"'the', 'worlddddddddddddddddddddd']}")
有没有办法在 f-strings 中完成这项工作,所以我不必 pp.pprint(my_dict) ?

最佳答案

并不真地。您能做的最接近的是使用 pformat , 即 pprint没有 print .

print(f"Let's talk about all of these things:\n\n{pp.pformat(my_dict)}")

关于python - 如何漂亮地打印 f 字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65720934/

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