我正在尝试从带有括号的原始输入中打印我的字符串。
这是我的代码。
words = (raw_input('Please enter a string: '))
names = list(words)
print names
我得到这个:
['H', 'e', 'l', 'l', 'o']
我只需要这样:
[Hello]
您不需要list
,只需使用format
或%s
:
words = raw_input('Please enter a string: ')
names = '[{}]'.format(words) # or '[%s]'%words
print names
如果用户写了多个单词,则可以先分割输入并打印出来(请注意,它们之间必须有空格):
print words.split()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句