output of following code fragment?

out = open("output.txt", "w")

1

out.write("Hello, world! \n")

2

out.write("How are you?")

3

out.close()

4

print (open("output.txt").read())

5

Hello, world! How are you?'

The output will be:

The first line of the code is opening the file in write mode;

the next two lines write text to the file. The last line opens the file and from that reference reads the file-content.

Function file() does the same as that of open().

Thus file("output.txt") will give the reference to open file, on which read() is applied.