python - 如何在Python中连续打印多行文本(一个相邻)
问题描述
所以,如果我得到例如:
print("some text\n
some more text\n
yet some more text")
和:
print("another some text\n
another some more text\n
yet another some more text")
如何在不这样做的情况下将它们彼此相邻打印:
print("some text another some text\n
some more text another some more text\n
yet some more text yet another some more text")
我不想做我刚刚向您展示的内容,因为我将生成更多具有不同文本和值的列,但我希望它们彼此相邻并带有\n
中断。
我怎样才能在 Python 中做到这一点?
解决方案
一个简单的方法是循环遍历字符串列表,如下所示:
column_1 = ["some text", "some more text", "yet some more text"]
column_2 = ["another some text", "another some more text", "yet another some more text"]
for i in range(0, len(column_1 )):
print("{}\t{}".format(column_1[i], column_2[i]))
当然,如果两列的长度相同。如果你想更好地对齐它们,你可以更巧妙地使用标签。
推荐阅读
- mobile - Magento 2 - 如何在 Luma 子主题中制作响应式布局?
- docker - System.Net.Http.HttpRequestException:连接被拒绝
- css - 如何自定义 Angular Material 分页器的 css?
- android - 安卓实时安装TTS语音数据
- relationship - 如何将 MySQL 查询转换为 Eloquent 关系?
- apache-flink - Flink - 如何通过 JMX Reporter 导出 flink 的 kafka 连接器偏移量?
- javascript - 鼠标离开故障
- java - 整数迭代帮助java
- php - 在codeigniter中使用更新查询时如何用逗号替换值?
- c - 按出发日期对航班进行排序