[英]Print a word with space after each character that was inserted in an input using python
I would like to print the result of a text or word that is digited at a input with space between every character/letter/number, how can i do it with python?我想打印在每个字符/字母/数字之间有空格的输入中数字化的文本或单词的结果,我该如何使用 python 来实现?
I did some searchs, but i only found the code for 2 or more characters...我做了一些搜索,但我只找到了 2 个或更多字符的代码......
As John said in the comments, you can use str.join
for this:正如约翰在评论中所说,您可以为此使用
str.join
:
>>> x = input()
Hello
>>> ' '.join(x)
'H e l l o'
If you mean to split text like this: 'lorem ipsum'
to ['lorem','ipsum']
, you could use x = string.split()
.如果您打算像这样拆分文本:
'lorem ipsum'
到['lorem','ipsum']
,您可以使用x = string.split()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.