How to write list of strings to file, adding newlines?
问题 def generator(): nums = ['09', '98', '87', '76', '65', '54', '43'] s_chars = ['*', '&', '^', '%', '$', '#', '@',] data = open("list.txt", "w") for c in s_chars: for n in nums: data.write(c + n) data.close() I would like to add a newline after every "c + n". 回答1: Change data.write(c + n) to data.write("%s%s\n" % (c, n)) 回答2: A properly-placed data.write('\n') will handle that. Just indent it appropriately for the loop you want to punctuate. 回答3: As other answers gave already pointed out, you