从键盘上输入一个列表,在键盘上输入形式:[1,2,3,5,6]
直接上代码
x = input()
x = x.strip('[')
x = x.strip(']')
xlist = x.split(',')
xlist = [int(xlist[i]) for i in range(len(xlist))]
print(xlist)
从键盘键入[1,2,3,5,6]
运行结果:
[1, 2, 3, 5, 6]
Process finished with exit code 0