Question:

Explain the shortest way to open a text file and display its contents.?

Answer:

The shortest way to open a text file is by using “with” command as follows:

with open("file-name", "r") as fp:
fileData = fp.read()
#to print the contents of the file print(fileData)

Keywords:

© 2017 QuizBucket.org