如何在python中将垂直字符串旋转为水平字符串? [关闭]

问题描述 投票:-2回答:1

我尝试使用那些脚本,但是它们不起作用。

print "".join(input.split())

input.replace("\n", "")

(如果可以,请尝试解释您的答案)

python string short
1个回答
0
投票
s1 = "abcd1234" # some horizontal string
s2 = "" # another string: we will use this to store verical form of s1
for i in s1:
    s2 = s2 + i + '\n'

您只需要在字符串中的每个字符之后输入换行符(\n)。就这么简单!

© www.soinside.com 2019 - 2024. All rights reserved.