2014-01-14 24 views
1

我试图将用户的RAW输入数据转换为Python中的字符数组。在Python中转换字符数组中的原始数据

>>> print 'your have entered:'+ userinput 
>>> arrname=[] 

我想存储在arrname作为一个字符数组的userinput,但我真的不知道该怎么做。

+4

你为什么想这么做? Python字符串可以像列表一样使用 – thefourtheye

回答

1

使用 '的raw_input()' 这里是doc

所以对你来说会是这样的:

userinput = raw_input("enter something:") 

然后,您可以将其转换通过列出:

arrname = list(userinput) 
3

使用list功能:

>>> userinput = 'userinput' 
>>> list(userinput) 
['u', 's', 'e', 'r', 'i', 'n', 'p', 'u', 't'] 

正如thefourtheye评论,你可以使用像列表字符串(除了修改它)。例如,你可以迭代每个字符。

>>> for ch in userinput: 
...  print(ch) 
... 
u 
s 
e 
r 
i 
n 
p 
u 
t 
相关问题