嗨,我怎么能在这段代码的最后一行的z中添加其他元素,即z [i]
z = [2,3,4,5]
my_file.write('%s' % j + 'a' + ':' + str(z[0]) + ',')#z[0] = first element in z
由于
答案 0 :(得分:0)
z = [2,3,4,5]
with open("output.txt", 'w') as my_file:
my_file.write('a: %s' % ', '.join([str(i) for i in z]))
output.txt的:
a: 2, 3, 4, 5