python print %-20s
时间: 2023-08-20 15:13:36 浏览: 218
回答: 在Python中,使用print函数进行字符串格式化输出时,可以使用%-20s来实现左对齐并占位20位的效果。\[3\]这里的%s表示字符串格式化,而%后面的-表示左对齐,20表示占位符的宽度为20位。所以,当我们使用print("%-20s" % str)时,会将字符串str左对齐并占位20位输出。
#### 引用[.reference_title]
- *1* [Python_%---format_43](https://blog.csdn.net/weixin_34082789/article/details/94014736)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [python 0基础学习笔记——print()、格式化 %,format()](https://blog.csdn.net/shujingsnail/article/details/123025268)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文