打印两列字符串 [英] Printing string with two columns

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

问题描述

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

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)

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

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