CBSE Class 12 Computer Science Question 107 of 136

Data File Handling — Question 46

Back to all questions
46
Question

Question 46

Write a statement in Python to perform the following operations:

(a) To open a text file "BOOK.TXT" in read and append mode

(b) To open a text file "BOOK.TXT" in write mode

(c) To open a text file "BOOK.TXT" in append mode

Answer

(a) To open a text file "BOOK.TXT" in read and append mode :
file_read_append = open("BOOK.TXT", "a+")

(b) To open a text file "BOOK.TXT" in write mode :
file2 = open("BOOK.TXT", "w")

(c) To open a text file "BOOK.TXT" in append mode :
file_append = open("BOOK.TXT", "a")