在同一行上打印多行字符串(ASCII ART)的最佳和最短方法,即使高度不同
# Rock
rock = ("""Rock
_______
---' ____)
(_____)
(_____)
(____)
---.__(___)
""")
# Paper
paper = ("""Paper
_______
---' ____)____
______)
_______)
_______)
---.__________)
""")
# Scissors
scissors = ("""Scissors
_______
---' ____)____
______)
__________)
(____)
---.__(___)
""")
如何在同一行上打印这些多行字符串?
我正在寻找最简单,最短的方法 我尝试了一些我看到的技巧,但到目前为止没有运气。
谢谢
# Rock
rock = ("""Rock
_______
---' ____)
(_____)
(_____)
(____)
---.__(___)
""")
# Paper
paper = ("""Paper
_______
---' ____)____
______)
_______)
_______)
---.__________)
""")
# Scissors
scissors = ("""Scissors
_______
---' ____)____
______)
__________)
(____)
---.__(___)
""")
how can I print these multiline strings at the same line?
I'm looking for the simplest and shortest way
I tried few tricks that I saw, but no luck so far.
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一条线上的任意数量图像(纸张有额外的手指来证明它仍然适用于不同的图像尺寸):
Arbitrary number of images on one line (paper got an extra finger to demonstrate that it still works for different image sizes):
更灵活?
评论
rock
等是单包含一些newline字符的字符串,我们想在同一条线上打印一条来自Rock ,
paper
的行,剪刀
的一行,因此我们需要做的第一件事是拆分每个字符串以获取列表的列表字符串,但我们确实需要
,也就是字符串列表的转换,但这是python中的一个众所周知的成语(这不是真正的列表,但是…),
这是我们可以在此时打印的每个元素的每个三重元素
transpoded_list
使用适当的格式(%-25S
输出字符串长25个字符,右侧为空白)。使该功能作为练习……
sub -commentary
imo,尽可能地不应提供副作用,例如打印。
More flexibility?
Commentary
rock
, etc are single strings containing a few newline characters, and we want to print, on the same line, a line fromrock
, a line frompaper
and one fromscissors
, so the first thing that we need to do is to split each string to obtain a list of list of stringsbut we really need
that is, the transpose of the list of lists of strings, but this is a well known idiom in Python (it's not really a list, but…)
at this point we can print each triple of elements in the
transposed_list
using an appropriate format (%-25s
outputs a string 25 characters long, blank filled on the right).Making this a function is left as an exercise…
Sub—commentary
IMO, as far as possible a function shouldn't provide side effects, like printing.