Python:分两列打印 [英] Python: print in two columns

查看:638
本文介绍了Python:分两列打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试打印带有两个固定列的字符串.例如,我希望能够打印:

I'm trying to print a string with two fixed columns. For example, I'd like to be able to print:

abc       xyz
abcde     xyz
a         xyz

在打印时格式化输出字符串的正确方法是什么?另外,该如何在2.6版之前和2.6版之后完成?

What is the correct way to format the output string when printing to achieve this? Also, how is this done before version 2.6 and after version 2.6?

推荐答案

您可以使用格式并在列之间提及修订空间

You can use format and mention fix spaces between columns

'{0:10}  {1}'.format(s1, s2)

旧样式格式

'%-10s' '%s' % (s1,s2)

这篇关于Python:分两列打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆