Pet*_*ost 10 python list python-3.x
我想知道如何获取用户输入并列出其中的每个字符.
magicInput = input('Type here: ')
Run Code Online (Sandbox Code Playgroud)
并且说你输入了"python rocks"我想让它成为这样的列表
magicList = [p,y,t,h,o,n, ,r,o,c,k,s]
Run Code Online (Sandbox Code Playgroud)
但如果我这样做:
magicInput = input('Type here: ')
magicList = [magicInput]
Run Code Online (Sandbox Code Playgroud)
magicList就是
['python rocks']
Run Code Online (Sandbox Code Playgroud)
gtl*_*ert 11
使用内置list()功能:
magicInput = input('Type here: ')
magicList = list(magicInput)
print(magicList)
Run Code Online (Sandbox Code Playgroud)
产量
['p', 'y', 't', 'h', 'o', 'n', ' ', 'r', 'o', 'c', 'k', 's']
Run Code Online (Sandbox Code Playgroud)