Q. Write the file mode that will be used for opening the following files. Also, write the Python statements to open the following files:
a) a text file "example.txt" in both read and write mode
b) a binary file "bfile.dat" in write mode
c) a text file "try.txt" in append and read mode
d) a binary file "btry.dat" in read only mode.
Answer :-
a = In W+ mode example :- file = open( "example.txt", "w+" )
b = In wb mode example :- file = open("bfile.dat" , "wb" )
c = In a+ mode Example :- file = open ( "try.txt" , "a+" )
d = In rb mode Example :- file = open( "btry.dat" , "rb" )
b = In wb mode example :- file = open("bfile.dat" , "wb" )
c = In a+ mode Example :- file = open ( "try.txt" , "a+" )
d = In rb mode Example :- file = open( "btry.dat" , "rb" )
The (d) answer is
ReplyDeletefile = open( "btry.dat" , "rb")
Sorry, I have corrected it.
Deletethe (a) answer is
ReplyDeletefile = open("exmaple.txt",r+)
its not w+
both are correct.
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )