Zed-King Institute
    All Notes

    O Level · Chapterwise MCQ

    Chapter 7: File Processing — MCQ

    Zed-King Study app · Free

    O Level students across India practise here, free

    Daily M1–M4 quizFull 100-question mocksAll-India rank
    Open the free app

    Google login · no Play Store needed

    🏆 Free All-India Sunday Mock · Sun, 29 Nov, 11 AM · CCC + O LevelRegister

    About this PDF

    Chapter 7 — questions on opening, reading and writing files, file modes and the read, readline, readlines, tell and seek methods.

    This is part of the free O Level M3-R5.1 study material in the Zed-King Study Zone. You can read every page above in your browser, or download the file and study offline. Zed-King Group of Institute is a NIELIT Study Centre in Kaithal, Haryana, and all of this material follows the current NIELIT syllabus.

    Course
    O Level — NIELIT Foundation Diploma
    Module
    M3 — M3-R5.1: Programming and Problem Solving through Python
    Section
    Chapterwise MCQ
    Format
    PDF — read online or download
    Price
    Free, no sign-up required

    Text from this PDF

    The opening pages as plain text — open the reader above for tables, diagrams and the full file.

    Chapter-7 File Handling

    Q1. Which statement will return one line from file(file object is ‘f’). · Ans. f.readline()

    Q2. Which is used to store data permanently. · Ans. File

    Q3. Readlines() ,method return · Ans. List

    Q4. Tell function returns the _____ · Ans. current position of a file pointer.

    Q5. When we open a file in append mode the file pointer is at the _____ of the file. · Ans. End

    Q6. _____ function takes a list of lines to be written to file. · (a) writelines() (b) write() (c) tell() (d)

    None

    Q7. What is the use of seek() method in files? · (a) Sets the file’s current position at the offset · (b) Sets the file’s previous position at the offset · (c) Sets the file’s current position within the file · (d) None

    Q8. ___________is used to close a file objects(fp). · (a) close.fp (b) fp.close() (c) file.exit() (d)

    none

    Q9. _________ are modes of both writing and reading in binary format in file. · (a) bw+ (b)

    wb+ (c)

    rb+ (d) None

    Q10. Which function is used to writes the string(s) to the file and returns the number of characters written. · (a) writelines(s) (b) read(s) · (c) write(s) (d) None

    Q11. What is the current syntax of remove a file? · (a) remove( (),file_name) · (b)remove(new_file_name,current_file_ name) · (c) remove(file_name) · (d) All of these

    Q12. Correct syntax of file.writelines()

    is?

    (a) file.writelines(sequence) (b)

    fileObject.writelines()

    (c) (fileObject.writelines sequence) (d)

    None

    Q13. Which of the following mode argument is used to truncate? · (a) a (b) f (c) w (d) t

    Q14. To open a file c:\balaji.txt for reading , we use______ · (a) infile=open(“c:\balaji.txt”,”r”) (b)

    infile=open(“c:\\balaji.txt”,”r”)

    (c) infile=open(file=“c:\balaji.txt”,”r”)

    (d) None

    Q15.Which of the following mode will refer to binary data? · (a) r (b) w (c) + (d)b

    Q16. What error is returned by the following statement if the file does not exist? · (a) filenotfounderror (b) notfounderror · (c) filenotfound (d) founderror

    Q17. Which statement will open file “data.txt” in append mode? · (a) f=open(“data.txt,”a”) · (b) f=open(“data.txt,”ab”) · (c) f=new(“data.txt,”a”) · (d) open(“data.txt,”a”)

    Q18.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

    Q19. Each line of a text file is terminated by a special character, called the ________ · (a) end of file (b) end of line · (c) end of statement · (d) end of program

    Q20. A text file contains only textual information consisting of _________ · (a) Alphabets (b) numbers · (c) special symbols (d) All of these

    Q21. Amongest which of the following is/are needed to open an existing file? · (a) filename (b) mode (c) both a and b · (d) All of these

    Q22.Method is used to display entire contents of the file. · (a) readlines() (b) read() (c) both a & b · (d) none

    Q23. What will be the output of the following code?

    f=open(“demo.txt”,”w+”)

    f.write(“welcome in python”)

    f.seek(5)

    a=f.read(5)

    print(a)

    (a) welco (b) me to (c) welcome to python (d) e to

    Q24. The syntax used to rename a file: · (a) os.rename(existing_name,new_nam · (b) fp.name=’new-name.txt’ · (c) os.rename(fp,new_name)

    +(d)os.set_name(existing_name,new_n ame)

    Q25. Which of the following is not a correct mode to opne a file? · (a) ab (b) rw (c) a+ (d) r+

    Q26.what will be the output of the following code?

    f=open(“demo.txt”,”r”)

    print(f.tell())

    Q27. If we open a file in write mode and file does not exists , which of the error will generate? · (a) File Found Error (b) File Not Exist Error (c) File Not Found Error (d) None

    Q28. 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

    Q29.which of the following error is returned by the given code?

    >>> f=open(“test.txt”,”w”)

    >>> f.write(345)

    (a) Syntax error (b) Type error (c)

    String Error (d) Run Time Error

    Q30. What is ‘f’ in the following statement? · (a) File Name (b) File Handle (c) Mode of file (d) File Handling

    More chapterwise mcq for M3-R5.1

    Run these Python programs yourself — free

    Reading code is not the same as writing it. Type any program from these notes into our free online Python compiler (real Python 3 with NumPy, input() works), or study one of the explained programs with its output.

    Prepare for O Level with expert guidance

    Classroom training, practical labs and exam registration at Zed-King Institute, Kaithal.

    Drag me!