Let us now try writing to our text file. For that, we will use the 'a' mode. We can also use the 'w' mode, but that will erase all existing data from the file if it exists. The program below shows how it works.
f = open('woohoo.txt', 'a')
f.write('\nThis sentence will be appended with new data')
f.write('\nwe fall and guys')
f.close()
Here we use the write() function to append the sentences 'This sentence will be appended with new data' and 'we fall and guys' to the file, each starting on a new line since we used '\n'. The file will now have the data
in order to guys,
you need to fall
but what if, in order to fall
you need to guys
This sentence will be appended with new data
we fall and guys
No comments:
Post a Comment