CBSE CS and IP

CBSE Class 11 & 12 Computer Science and Informatics Practices Python Materials, Video Lecture

File Handling (1 Mark Questions)


  1. What is the output of the following code?
    f = None
    for i in range (5):
        with open("data.txt", "w") as f:
            if i > 2:
                break
    print(f.closed)
    a) True    b) False    c) None    d) Error
    

  2. To open a file c:\books.txt for reading, we use:
    a) infile = open("c:\books.txt", "r")   
    b) infile = open("c:\\books.txt", "r")
    c) infile = open(file = "c:\books.txt", "r")  
    d) infile = open(file = "c:\\books.txt", "r")
    

  3. Write a statement in Python to perform the following operations :
    1. To open a text file “BOOK.TXT” in read mode
    2. To open a text file “BOOK.TXT” in write mode

  4. Which of the following File Modes creates a new file, if the file does not exist? (choose one/more)
    • 'r'
    • 'bw'
    • 'w'
    • 'a'

  5. In which of the following mode the existing data of the file will not be lost?(choose one/more)
    • 'rb'
    • 'wb'
    • 'w+'
    • 'r+'

  6. In which of the following file modes the existing data of the file will not be lost?
    rb, ab, w, w+b, a+b, wb, wb+, w+, r+
  7. What will the output of the following code :
    1
    2
    3
    f1 = open("test1.txt","r")                                      
    size = len(f1.read())
    print(f1.read(5))
    
  8. Differentiate between r+ and w+ with respect to Python file handling.

1 comment:

  1. very helpful.thanks for your supportive upload

    ReplyDelete