python zip功能出现故障

时间:2018-06-03 06:22:32

标签: python python-3.x

first_len = [15,20,25,30,35]
meas_len = []
meas_len_ipt = input("type 5 values separated by comma:")
meas_len.append(meas_len_ipt)


for fl, ml in list(zip(first_len,meas_len)):
    print(fl,ml)


input('Press ENTER to exit')

我打算

15 1
20 2
25 3
30 4
35 5

出现,但结果是

15 1,2,3,4,5

1 个答案:

答案 0 :(得分:1)

输入时,

meas_len_ipt只是一个字符串。您需要将其拆分为单个元素:

meas_len_ipt = input("type 5 values separated by comma:")
meas_len = meas_len_ipt.split(",")