w3resource logo


Python Exercises

Python File I/O: Append text to a file and display the text

Python File I/O: Exercise-3 with Solution

Write a Python program to append text to a file and display the text.

Sample Solution:-

Python Code:

def file_read(fname):
        from itertools import islice
        with open(fname, "w") as myfile:
                myfile.write("Python Exercises\n")
                myfile.write("Java Exercises")
        txt = open(fname)

Sample Output:

Python Exercises                                                                                              
Java Exercises 

Python Code Editor:

Improve this sample solution and post your code through Disqus