Loading

Quipoin Menu

Learn • Practice • Grow

Direction: Choose the correct option

Q1.

Which function is used to open a file in Python?
A. open()
B. file()
C. io.open()
D. Both A and C
Direction: Choose the correct option

Q2.

What does `open('file.txt', 'r')` do?
A. Creates a new file
B. Opens file.txt for reading
C. Opens file.txt for appending
D. Opens file.txt for writing
Direction: Choose the correct option

Q3.

How do you read all lines of a file into a list?
A. f.read()
B. f.readall()
C. f.readline()
D. f.readlines()
Direction: Choose the correct option

Q4.

What is the correct way to write to a file?
A. f.writelines('text')
B. f.write('text')
C. f.add('text')
D. f.print('text')
Direction: Choose the correct option

Q5.

What does the `with` statement do in file handling?
A. Automatically closes the file after the block
B. Opens the file
C. Creates a backup
D. Locks the file
Direction: Choose the correct option

Q6.

What mode would you use to open a file for writing, creating if not exists?
A. 'x'
B. 'a'
C. 'w'
D. 'r'
Direction: Choose the correct option

Q7.

How do you check if a file exists before opening?
A. os.path.exists()
B. file.exists()
C. path.exists()
D. os.isfile()
Direction: Choose the correct option

Q8.

What is the difference between 'w' and 'a' modes?
A. Both append
B. Both overwrite
C. 'w' appends, 'a' overwrites
D. 'w' overwrites, 'a' appends
Direction: Choose the correct option

Q9.

What does `f.seek(0)` do?
A. Sets the file position to 0
B. Moves to end
C. Moves the file pointer to the beginning
D. Both A and C
Direction: Choose the correct option

Q10.

What is the output of `open('test.txt', 'x')` if file already exists?
A. FileExistsError
C. Creates a new file
D. Overwrites