我有这段代码:
a = []
num = input('Enter numbers *Separate by using commas:')
for i in num:
a.append(i)
print(a)
我得到了这个:
Enter numbers *Separate by using commas:1,2,3
['1', ',', '2', ',', '3']
如何删除逗号?..我需要使用for循环...谢谢
答案 0 :(得分:1)
您可以使用此功能(默认情况下会阻止","首先输入您的阵列,并按照您的指示使用多位数功能) -
a = []
num = input('Enter numbers *Separate by using commas:')
num = num.split(",") #splits the input string with "," delimiter
for i in num:
a.append(i)
print(a)