Python Files Interview Questions: Files in Python language

Python Files Interview Questions. Multiple Choice Questions And Answers on Files in Python programming.

 

Python Files Interview Questions

 

 

What happens if no arguments are passed to the seek function ??

a) file position is set to the start of file
b) file position is set to the end of file
c) file position remains unchanged
d) error

 

Which of the following are the modes of both writing and reading in binary format in file ??

a) wb+
b) w
c) wb
d) w+

 

How do you change the file position to an offset value from the start ??

a) fp.seek(offset, 0)
b) fp.seek(offset, 1)
c) fp.seek(offset, 2)
d) none of the mentioned

 

Is it possible to create a text file in python ??

a) Yes
b) No
c) Machine dependent
d) All of the mentioned

 

How do you delete a file ??

a) del(fp)
b) fp.delete()
c) os.remove(‘file’)
d) os.delete(‘file’)

 

Which function is used to close a file in python ??

a) Close()
b) Stop()
c) End()
d) Closefile()

 

How do you rename a file ??

a) fp.name = ‘new_name.txt’
b) os.rename(existing_name, new_name)
c) os.rename(fp, new_name)
d) os.set_name(existing_name, new_name)

 

Which function is used to write a list of string in a file ??

a) writeline()
b) writelines()
c) writestatement()
d) writefullline()

 

How do you get the current position within the file ??

a) fp.seek()
b) fp.tell()
c) fp.loc
d) fp.pos

 

Which function is used to write all the characters ??

a) write()
b) writecharacters()
c) writeall()
d) writechar()

 

How do you close a file object (fp) ??

a) close(fp)
b) fclose(fp)
c) fp.close()
d) fp.__close__()

 

Which function is used to read single line from file ??

a) Readline()
b) Readlines()
c) Readstatement()
d) Readfullline()

 

Which of the following is not a valid attribute of a file object (fp) ??

a) fp.name
b) fp.closed
c) fp.mode
d) fp.size

 

Which function is used to read all the characters ??

a) Read()
b) Readcharacters()
c) Readall()
d) Readchar()

 

How do you get the name of a file from a file object (fp) ??

a) fp.name
b) fp.file(name)
c) self.__name__(fp)
d) fp.__name__()

 

What is the use of “a” in file handling ??

a) Read
b) Write
c) Append
d) None of the mentioned

 

What is the difference between r+ and w+ modes ??

a) no difference
b) in r+ the pointer is initially placed at the beginning of the file and the pointer is at the end for w+
c) in w+ the pointer is initially placed at the beginning of the file and the pointer is at the end for r+
d) depends on the operating system

 

What is the use of “w” in file handling ??

a) Read
b) Write
c) Append
d) None of the mentioned

 

Which of the following is not a valid mode to open a file ??

a) ab
b) rw
c) r+
d) w+

 

In file handling, what does this terms means “r, a” ??

a) read, append
b) append, read
c) write, append
d) none of the mentioned

 

Read More

Leave a Comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!