

This takes care of closing the file for you. What follows is an idiomatic way in Python to write a list of strings to a file while keeping each string in its own line: lines = It actually behaves like an imaginary method called write_all_of_these_strings(sequence). The interesting part is that writelines() does not add newline characters on its own, so the method name can actually be quite confusing. they just write to the file whatever you provide them. The nature of the string(s) does not matter to both of the functions, i.e. A tuple of strings is what you provided, so things worked. Each item contained in the iterator is expected to be a string. Writelines(arg) expects an iterable as argument (an iterable object can be a tuple, a list, a string, or an iterator in the most general sense). If you provide a list of strings, it will raise an exception (by the way, show errors to us!). Write(arg) expects a string as argument and writes it to the file. If you have a sequence of strings you can write them all using writelines().

The idea is the following: if you want to write a single string you can do this with write().

Why am I unable to use a string for a newline in write() but I can use it in writelines()?
