1 Every file has its own identity associated with it. Which is known as –
a. icon
b. extension
c. format
d. file type
2 Which of the following is not a known file type?
a. .pdf
b. jpg
c. mp3
d. txp
1. In f=open(“data.txt”, “r”), r refers to .
a. File handle
b. File object
c. File Mode d Buffer
2. EOL stands for
a. End Of Line
b. End Of List
c. End of Lines
d. End Of Location
3. Which of the following file types allows to store large data files in the computer memory?
a. Text Files
b. Binary Files
c. CSV Files
d. None of these
4. Which of the following file types can be opened with notepad as well as ms excel?
a. Text Files
b. Binary Files
c. CSV Files
d. None of these
5. Which of the following is nor a proper file access mode?
a. close
b. read
c. write
d. append
11. In F=open("MyFile.txt") , name of file object is a.open
b.MyFile.txt c.F d.F=open()
12. Default EOL character in Python.
a. ‘\n’
b. ‘\r’
c. ‘’
d. ‘\t’
13. Which of the following is not a file extension for text files?
a. .txt
b. .ini
c. .rtf
d. .DAT
14. What is the first thing to do before performing any functions on a text file?
a. Import modules
b. Open file
c. Read file
d. Print the name of the file
15. What is a file object?
a. It serves as a link to the file.
b. It is a file present in a computer.
c. A keyword
d. A module in python
16. Which is not a correct file mode for text files?
a. a
b. ar
c. a+
d. r+
17. What does the prefix r in front of a string do?
a. It makes the string a raw string
b. It opens the file in read mode
c. It converts the file into text file
d. It creates the file if it doesn’t exist
18. A file object is also known as
a. File handle
b. File copy
c. File directory
d. File link
19. How to open a text file in read mode only?
a. r
b. r+
c. rb+
d. rw+
20. How to open a text file in write and read mode?
a. r+
b. a+
c. wr
d. wb
21. Syntax for closing a file:
a. closefile(<file object>)
b. <fileobject>.close()
c. <filename>.closer()
d. closefile.<fileobject>
22. Which method can not be used to read from files?
a. read()
b. readlines()
c. readlines(<filename>)
d. readline()
23. What does strip() function do?
a. Removes the trailing or leading spaces, if any.
b. Deletes the file
c. Remove the file object
d. Removes all the spaces between words
24. readlines() gives the output as
a. List
b. Tuple
c. String
d. Sets
25. When reading a file using the file object, what method is best for reading the entire file into a single string?
a. readline()
b. read_file_to_str()
c. read()
d. readlines()
26. Which file can open in any text editor and is in human readable form?
a. Binary files
b. Text files
c. Data files
d. Video files
27. Which function breaks the link of file-object and the file on the disk?
a. close( )
b. open( )
c. tell( )
d. readline( )
28. Which function reads the leading and trailing spaces along with trailing newline character ('\n') also while reading the line?
a. readlines( )
b. readline( )
c. read( )
d. flush( )
29. Which mode is used to retain its previous data and allowing to add new data?
a. write mode
b. read mode
c. open mode
d. append mode
30. Which function forces the writing of data on disc still pending in output buffer?
a. seek( )
b. tell( )
c. flush( )
d. write( )
31. Syntax for flush( ) function is:
a. <fileOobject>(flush( ))
b. flush( ).<fileobject>
c. <fileObject>.flush( )
d. flush( ).<file-object>
32. Which function returns the entire file content in a list where each line is one item of the list?
a. readlines( )
b. readline( )
c. output( )
d. Input( )
33. Which function is used to remove the given character from trailing end i.e. right end?
a. strip( )
b. remove( )
c. Istrip( )
d. rstrip( )
34. Sometimes the last lap of data remains in buffer and is not pushed onto disk until a operation is performed.
a. dump( )
b. close( )
c. load( )
d. open( )
35. The position of a file-pointer is governed by the .
a. File mode b. append mode
c. write mode d. open mode
36. In which mode the file must exist already, otherwise python raises an error? a. read mode
b. write mode
c. binary mode
d. None of these
37. What is the prefix r stands for in file path?
a. raw string
b. read
c. write
d. append
38. In which mode if the file does not exist, then the file is created?
a. read write mode
b. read mode
c. write mode
d. All of these
39. Which option is correct about this program? f=open(“ss.txt”,”wb”)
print(“Name of the file:”,f.name) f.flush()
f.close()
a. Compilation error
b. Runtime error
c. No output
d. Flushes the file when closing them
40. What is the output of the following? import sys
sys.stdout.write(‘Hello\n’)
sys.stdout.write(‘Python\n’)
a. error
b. Runtime error
c. Hello Python
d. Hello
Python
41. Which function is used to read all the characters in text files?
a. read( )
b. readcharacters( )
c. readall( )
d. readchar( )
42. Which function is used to read all the lines?
a. read( )
b. readall( )
c. readlines( )
d. readline( )
43. In which format does the readlines( ) function give the output?
a. Integer type
b. list type
c. string type
d. tuple type
44. In which format does the read( ) function give the output?
a. Integer type
b. string type
c. list type
d. tuple type
4
45. Which function is used to write a list of strings in a file?
a. writestatement()
b. writelines()
c. writefulline()
d. writeline()
46. Which function is used to write all the characters?
a. writechar()
b. writecharacters()
c. write()
d. writeall()
47. What is the correct syntax of open() function?
a. file=open(file_name[,access_mode][,buffering])
b. fileobject=open(file_name[,access_model][,buffering])
c. fileobject=filename.open()
d. none of the mentioned
48. In file handling, what does means “r”, “a”?
a. append, read
b. read, append
c. read, add
d. None of the mentioned
49. The default file open mode is….
a. w
b. r+
c. w+
d. r
50. What is the difference between r+ and w+ modes?
a. In r+ mode, file length truncates to zero.
b. In w+ mode, file length truncates to zero either file exists or not.
c. No difference
d. Depends on the operating system
51. A file maintains a which tells the current position in the file where writing or reading will take place.
a. line
b. file pointer
c. list
d. order
52. Which of the following statements is true regarding the opening modes of a file? a. While opening a file for reading, if the file does not exist, an error occurs. b. While opening a file for writing ,if the file does not exist, an error occurs. c. While opening a file for reading, if the file does not exist, a new file is created. d. None of the above.
53. To force python to write the contents of file buffer on to storage file,........method may be used.
a. buffer()
b. flush()
c. close()
d. write()
54. Which of the following statements are true?
a) When you open a file for reading, if the file does not exist, an error occurs.
b) When you open a file for writing, if the file does not exist, a new file is created.
c) When you open a file for writing, if the file exists, the existing file content is overwritten with the new content.
d) All of the these
55. To read the next line of the file from a file object f1, we use:
a) f1.read(2)
b) f1.read()
c) f1.readline()
d) f1.readlines()