Top 1000+ Solved Problem Solving and Python Programming MCQ Questions Answer
Q. Is it possible to create a text file in python?
a. yes
b. no
c. machine dependent
d. all of the mentioned
Q. 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+
Q. 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
Q. 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 ()
Q. 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
Q. How do you get the current position within the file?
a. fp.seek()
b. fp.tell()
c. fp.loc
d. fp.pos
Q. 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)
Q. 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
Q. 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
Q. Which function overloads the == operator?
a. eq ()
b. equ ()
c. isequal ()
d. none of the mentioned