Class 12 Computer Science: Python Revision and File Handling Worksheet

This worksheet tests your understanding of fundamental Python concepts and file handling operations, crucial for Class 12 Computer Science.

Class 12CBSEComputer SciencemediumPractice
Preview · 10 questions
  1. Q1. Which of the following modes is used to open a file for both reading and writing, creating it if it doesn't exist, and overwriting its contents if it does?
    • 'r+'
    • 'w+'
    • 'a+'
    • 'x'
  2. Q2. What will be the output of the following Python code snippet? ```python def func(a, b=5): print(a - b) func(10) func(b=2, a=8) ```
    • 5 6
    • 5 -6
    • -5 6
    • -5 -6
  3. Q3. The `____` method in file handling is used to read at most 'n' bytes from the file.
  4. Q4. Which of the following is an immutable data type in Python?
    • List
    • Dictionary
    • Tuple
    • Set
  5. Q5. What is the purpose of the `with open(...) as f:` statement in Python?
    • It automatically closes the file object.
    • It ensures the file is created with write permissions.
    • It locks the file to prevent other processes from accessing it.
    • It buffers file operations for faster execution.

+ 5 more in the printable PDF.