Write
Lesson 5 of 12 in Coddy's File Handling in Python course.
Let's write something into a file!
To write into a file you must open the file in write ('w') or append ('a') mode.
'a' - will append to the end of the file
'w' - Will overwrite any existing content
Use the function write(content) on a file to write to it,
f = open('a.txt', 'w')
f.write('Some text')This will write 'Some text' to a.txt file, and the existing content will be overwritten!
Challenge
EasyWrite to the file 'c.txt' so that in the end the file will contain the text:
Hello World!In the beginning, the file contains the text (missing !):
Hello WorldUse the append or write to complete the task!
Do not print anything! we will do that for you.
Try it yourself
# Write code here