File Processing MCQ
Q1. Which function writes a list of lines in File?
A. Writelines()
B. Write()
C. Tell()
D. All of Above
Ans: A
Q2. Which is the current syntax for remove a file?
A. Remove(file_name)
B. move(file_name)
C. removecurrent(file_Name)
D. None of Above
Ans: A
Q3. Which function used for writing data in binary format?
A. Write
B. Output
C. Dump
D. Read
Ans: C
Q4. Write a correct syntax for file.writelines()
A. file.writelines(sequence)
B. fileobject.writelines(sequence)
C. Both A & B
D. None of Above
Ans:B
Q5. Which is not attributes of file?
A. Closed
B. Open
C. Softspace
D. Name
Ans: D
Q6. In Python, the primary use of the tell() method is that:
A. within the file, it tells the current position
B. within the file, it tells the end position
C. it tells us if the file is opened
D. none of the above
Ans: A
Q7. Which statement will move file pointer 10 bytes backward from current position?
A. f.seek(-10,0)
B. f.seek(-10,1)
C. f.seek(10,0)
D. None of above
Ans: A
Q8. Which mode creates a new line file if the file does not exist?
A. Write mode
B. Append mode
C. Both A & B
D. None of the these
Ans: C
Q9. Which function opens file in python?
A. open()
B. Open()
C. new()
D. None of these
Ans: A
Q10. Which of the following file can be opened in any text editor?
A. Binary
B. Text
C. Both of the Above
D. None of the Above
Ans: B
Q11. Ravi opened a file in Python using open () function but forgot to specify the mode. In which mode the file will open?
A. Write
B. Append
C. Read
D. Both read and write
Ans: C
Q12. To open a file c:\career.txt then we write
A. File=open(“c:\career.txt”,”r”)
B. File=open(“c:\\career.txt”,”r”)
C. File=open(“c:\careertxt”,”r”)
D. All of Above
Ans: B
Q13. Tell() is used for
A. Within file,it tells the end position
B. Within file, it tells the start of position
C. Within file it tells the current position
D. All of Above
Ans: C
Q14. What is mode for truncate?
A. A
B. W
C. T
D. R
Ans: B
Q15. Which function is used to close a file object(fp)
A. fp.close
B. fp.exit
C. close.fp
D. All of Above
Ans: A
Q16. Seek() in file is…………………………….
A. It tells the current position of file.
B. It sets the file’s current position at the offset.
C. It tells the previous position at the offset
D. It sets the previous position at the offset.
Ans: B
Q17. Which function tells the current position in the file?
A. Tell()
B. Seek()
C. Write()
D. Read()
Ans: A
Q18. Which function reads a single line from a file?
A. Read()
B. Readline()
C. Readlines()
D. Read(singleline)
Ans: B
Q19. Readlines() function reads and return
A. Single line from a file
B. A list of remaining lines of the entire file
C. Write multiple lines at same time
D. None of Above
Ans: B
Q20. What is access mode for writing and reading in binary format in file?
A. Bw+
B. Wb+
C. Rb+
D. Wa+
Ans: B
Q21. What is function for write a list of lines to the file?
A. Write()
B. Writelines(lines)
C. Writeline(line)
D. All of Above
Ans:B
Q22. What is function which writes string to the file and returns the number of characters written?
A. Writeline()
B. Write()
C. Writelines()
D. All of Above
Ans: B
Q23. When a file open for write mode and file does not exists then error comes
A. File does not exist
B. File exist error
C. File found error
D. All of Above
Ans: A
Q24. What is function which takes two arguments?
A. Dump()
B. Load()
C. Tell()
D. Seek()
Ans: A
Q25. Which function is used to read the remaining lines of the file from a file object infile?
A. Infile.read()
B. Infile.readlines()
C. Infile.readline()
D. All of Above
Ans: B
Q26. What is output of following code?
f=open(“career.txt”,”r”)
print(f.tell())
A. 0
B. 1
C. 5
D. 2
Ans: A
Q27. Which is not correct mode to open a file?
A. a
B. a+
C. r+
D. rw
Ans: D
Q28. A text file which contain only textual information then contains
A. Numbers
B. Alphabets
C. Special Symbols
D. All of Above
Ans: D
Q29. A text file which terminated by
A. End of File
B. End of Line
C. End of statement
D. End of Program
Ans: A
Q30. Which statement will open file “career.txt” in append Mode?
A. f=open(“career.txt”,”a”)
B. f=open(“career.txt”,”ab”)
C. open(“career.txt”,”ab”)
D. open(“career.txt”,”a”)
Ans: A
Q31. What is mode for binary file?
A. R
B. W
C. B
D. None of Above
Ans: C
Q32. We read the first line of a text file career.txt?
A. f=open(“career.txt”); f.read()
B. f=open(“career.txt”);f.readline()
C. open(“career.txt”); f.read()
D. f=open(“career.txt”);f.readlines()
Ans: B
Q33. We can rename file by syntax
A. f.rename(existing_name,new_name)
B. f.name=”career_txt”
C. f.rename(new_name , existing_name)
D. None of Above
Ans: A
Q34. Which pickle module is used to write data on binary file?
A. Dump()
B. Write()
C. Writebiary()
D. All of Above
Ans: A
Q35. Which function returns the current position of a file pointer?
A. Load()
B. Seek()
C. Tell()
D. All of Above
Ans: C
File MCQ Asked O Level Jan 2023 Exam NIELIT
Q36. What does readlines() method return ?
A. Dictionary
B. String
C. Tuple
D. List
Ans: D
Q37. When we open file in append mode the file pointer is at the _________ of the file.
A. anywhere in between the file
B. end
C. beginning
D. second line of the file
Ans: B
Q38. The correct extension of the Python file is …………………………
A. .py
B. .pyth
C. .python
D. None of these
Ans: A
Q39. Which error is returned when we try to open a file in write mode which
does not exist ?
A. File Found Error
B. File Not Exist Error
C. File Not Found Error
D. None of the above
Ans: C
Q40. In which format Binary file contains information?
A. Quick response code
B. Same format in which the data is held in memory
C. ASCII format
D. Unicode format
Ans: B
Q41. Which statement will return one line from a file (file object is ‘f’)?
A. f.readlines( )
B. f.readline( )
C. f.read( )
D. f.line( )
Ans: B
Q42. Which statement will move file pointer 10 bytes backward from current position?
A. f.seek(-10, 0)
B. f.seek(10, 0)
C. f.seek(-10, 1)
D. none of the above
Ans: A
Q43. A _____________ stores information in the form of a stream of ASCII or Unicode characters i.e. human readable.
A. Text file
B. Binary file
C. Both (A) and (B)
D. None of these
Ans: A
Q44. What is ‘f’ in the following statement?
f=open(“Data.txt”, “r”)
A. File Name
B. File Handle
C. Mode of file
D. File Object
Ans: D
Q45. Which mode creates a new file if the file does not exist ?
A. write mode
B. read mode
C. append mode
D. Both (A) and (C)
Ans: C
Q46. Which function returns the current position of file pointer?
A. get( )
B. tell( )
C. seek( )
D. cur( )
Ans: B
Q47. Which is stored data permanently?
A. Variable
B. File
C. Both of the above
D. None of the above
Ans: B
Q48. Which will read entire content of file (file object ‘f’) ?
A. f.reads( )
B. f.read( )
C. f.read(all)
D. f.read( * )
Ans: B
Q49. f.read(6) will read __________ from a file (file object ‘f’).
A. 6 characters
B. 6 words
C. 6 lines
D. None of the above
Ans: A
File MCQ Questions Video:
Comments