[英]Space between each character in python
I need a simple python code that lets you enter text and shows it with space between each character.我需要一个简单的 python 代码,它可以让您输入文本并在每个字符之间用空格显示它。
I have made something like this and it works but now I don't know how to make it with spaces我做了这样的东西,它可以工作,但现在我不知道如何用空格制作它
text = input("text: ")
print(f"{text}")
text = input("text: ")
text = ' '.join(list(text))
print(text)
text = input("enter text here")
words=text.split()
output=""
for word in words:
for letter in word:
output = output + letter + " "
print(output)
As mentioned in the comments, you are looking for the join method of a string.如评论中所述,您正在寻找字符串的连接方法。 It takes an iterable and concatenates it together using the string as separator.
它需要一个可迭代对象并使用字符串作为分隔符将其连接在一起。 As a string is an iterable itself you can simply do
由于字符串本身是可迭代的,您可以简单地做
' '.join('Hello')
>>> H e l l o
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.