首页IT科技python3中print函数的用法(python pprint.pformat()函数的使用)

python3中print函数的用法(python pprint.pformat()函数的使用)

时间2025-08-04 02:10:37分类IT科技浏览6545
导读:1、返回要打印的内容的文本字符串,这个字符串既易于阅读,也是语法上正确的Python代码。 importpprint cats=[{...

1             、返回要打印的内容的文本字符串             ,这个字符串既易于阅读                        ,也是语法上正确的Python代码                。

importpprint cats=[{name:Zophie,desc:chubby},{name:Pooka,desc:fluffy}] pprint.pformat(cats) fileObj=open(myCats.py,w) fileObj.write(cats=+pprint.pformat(cats)+\n) fileObj.close()

2                        、如果来自pprint.pformat()的字符串保存为.py文件       ,该文件就是可以导入的模块                    。

importmyCats myCats.cats myCats.cats[0] myCats.cats[0][name]

以上就是python pprint.pformat()函数的使用         ,希望对大家有所帮助        。更多Python学习指路:Python基础教程

创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

展开全文READ MORE
手写promise知乎(300秒带你手写一个promise) 周宁在那里(周宁县怎么样)