Edzy
AI TutorResourcesToolsCompareBuy
SearchDownload AppLogin
Edzy

Edzy for Classes 6-12

Edzy is a personal AI tutor for CBSE and State Board students, with curriculum-aligned guidance, practice, revision, and study plans that adapt to each learner.

  • Email: always@edzy.ai
  • Phone: +91 96256 68472
  • WhatsApp: +91 96256 68472
  • Address: Sector 63, Gurgaon, Haryana

Follow Edzy

Browse by Class

  • CBSE Class 6
  • CBSE Class 7
  • CBSE Class 8
  • CBSE Class 9
  • CBSE Class 10
  • CBSE Class 11
  • CBSE Class 12
Explore the CBSE resource hub

Explore Edzy

  • Study Resources
  • Free Study Tools
  • Best Apps for Board Exams
  • Edzy vs ChatGPT
  • About Us
  • Why We Built Edzy
  • Blog
  • CBSE AI Tutor

Support & Legal

  • Help & FAQs
  • Accessibility
  • Privacy Policy
  • Terms & Conditions
  • Refund Policy
  • Cookie Policy
  • Site Directory

© 2026 Edzy. All rights reserved.

Curriculum-aligned learning paths for students in Classes 6-12.

CBSE
Class 12
Computer Science
Computer Science
File Handling in Python
Question Bank

Question Bank - File Handling in Python

Practice Hub

Question Bank: File Handling in Python

This chapter covers file handling in Python, including how to open, read, write, and manage text and binary files. Understanding file handling is crucial for data storage and manipulation in programming.

Structured practice

Question Bank - File Handling in Python

Q1.

What is the purpose of a file in Python?

Single Answer MCQ
Q-00094639
View explanation
Q2.

Which of the following is an example of a text file?

Single Answer MCQ
Q-00094640
View explanation
Q3.

What character typically indicates the end of a line in a text file in Python?

Single Answer MCQ
Q-00094641
View explanation
Q4.

What types of characters are stored in a binary file?

Single Answer MCQ
Q-00094642
View explanation
Q5.

Which of the following extensions corresponds to a text file?

Single Answer MCQ
Q-00094643
View explanation
Q6.

Which of the following best describes how data is stored in files?

Single Answer MCQ
Q-00094644
View explanation
Q7.

What function is used in Python to open a file?

Single Answer MCQ
Q-00094645
View explanation
Q8.

What mode should you use to write to an existing file without deleting its contents?

Single Answer MCQ
Q-00094646
View explanation
Q9.

What happens if you try to open a file that does not exist in read mode?

Single Answer MCQ
Q-00094647
View explanation
Q10.

When saving a text file, which encoding is commonly used?

Single Answer MCQ
Q-00094648
View explanation
Q11.

In Python, how can you read the entire content of a file?

Single Answer MCQ
Q-00094649
View explanation
Q12.

What is the function of the close() method in file handling?

Single Answer MCQ
Q-00094650
View explanation
Q13.

What module is used for handling object serialization in Python?

Single Answer MCQ
Q-00094651
View explanation
Q14.

In the context of text files, what does EOL stand for?

Single Answer MCQ
Q-00094652
View explanation
Q15.

If a text file contains the string 'Hello World' followed by a newline character, how many bytes does it contain?

Single Answer MCQ
Q-00094653
View explanation
Q16.

What is the primary difference between text files and binary files?

Single Answer MCQ
Q-00094654
View explanation
Q17.

Which of the following defines a text file?

Single Answer MCQ
Q-00094670
View explanation
Q18.

What character typically indicates the end of a line in a text file?

Single Answer MCQ
Q-00094671
View explanation
Q19.

Which of the following file extensions typically indicates a binary file?

Single Answer MCQ
Q-00094672
View explanation
Q20.

Why are binary files not human-readable?

Single Answer MCQ
Q-00094673
View explanation
Q21.

Which function is used in Python to open files?

Single Answer MCQ
Q-00094674
View explanation
Q22.

What distinguishes a text file from a binary file in terms of content?

Single Answer MCQ
Q-00094675
View explanation
Q23.

If you attempt to open a non-existent file in write mode using Python, what happens?

Single Answer MCQ
Q-00094676
View explanation
Q24.

What type of data do CSV files typically store?

Single Answer MCQ
Q-00094677
View explanation
Q25.

When using the open() function in Python, what does the 'r' mode signify?

Single Answer MCQ
Q-00094678
View explanation
Q26.

What would happen if you try to read from an unopened text file using Python?

Single Answer MCQ
Q-00094679
View explanation
Q27.

What is the main difference between a .py file and a .txt file?

Single Answer MCQ
Q-00094680
View explanation
Q28.

Which character is typically used to denote the end of a record in text files?

Single Answer MCQ
Q-00094681
View explanation
Q29.

In terms of complexity, how do binary files typically manage errors compared to text files?

Single Answer MCQ
Q-00094682
View explanation
Q30.

Which of the following statements about file handling in Python is correct?

Single Answer MCQ
Q-00094683
View explanation
Q31.

Which mode must be used to completely overwrite a text file when writing?

Single Answer MCQ
Q-00094684
View explanation
Q32.

What method is used to write multiple lines of text to a file in Python?

Single Answer MCQ
Q-00094685
View explanation
Q33.

In Python, which statement correctly opens a file called 'data.txt' in write mode?

Single Answer MCQ
Q-00094686
View explanation
Q34.

Which of the following is a reason to use the 'with' statement when handling files?

Single Answer MCQ
Q-00094687
View explanation
Q35.

What will be the result of running the following code: 'myfile.write(42)' without converting 42 to a string?

Single Answer MCQ
Q-00094688
View explanation
Q36.

Which method would you use to get the number of characters written to a file by the write() function?

Single Answer MCQ
Q-00094689
View explanation
Q37.

What is the outcome of opening a file in write mode if the file already contains data?

Single Answer MCQ
Q-00094690
View explanation
Q38.

How do you write a single string followed by a newline character to a file using the write method?

Single Answer MCQ
Q-00094691
View explanation
Q39.

If you want to ensure data is not only written but also immediately flushed to the file, which method is essential?

Single Answer MCQ
Q-00094692
View explanation
Q40.

Which is a necessary step after writing to a file?

Single Answer MCQ
Q-00094693
View explanation
Q41.

What happens if you attempt to write to a closed file?

Single Answer MCQ
Q-00094694
View explanation
Q42.

Which of these functions can help convert a number to a string before writing to a text file?

Single Answer MCQ
Q-00094695
View explanation
Q43.

Which of the following statements is true about the append mode for files?

Single Answer MCQ
Q-00094696
View explanation
Q44.

When using the write() method, what must be included after the string to ensure proper formatting in a text file?

Single Answer MCQ
Q-00094697
View explanation
Q45.

What does the tell() method in Python's file handling return?

Single Answer MCQ
Q-00094698
View explanation
Q46.

If a file object is currently at byte position 10, what will file_object.seek(5) do?

Single Answer MCQ
Q-00094699
View explanation
Q47.

What is the default reference point for the seek() function?

Single Answer MCQ
Q-00094700
View explanation
Q48.

What will file_object.seek(0, 1) do?

Single Answer MCQ
Q-00094701
View explanation
Q49.

How does seek() work with EOL characters in text files?

Single Answer MCQ
Q-00094702
View explanation
Q50.

What is the result of file_object.seek(2, 2) if the file is 5 bytes long?

Single Answer MCQ
Q-00094703
View explanation
Q51.

What is the appropriate syntax for seeking to byte 10 in a file?

Single Answer MCQ
Q-00094704
View explanation
Q52.

Which file mode allows both reading and writing to a file in Python?

Single Answer MCQ
Q-00094705
View explanation
Q53.

If you want to read from a specific byte in a file, which combination of functions would typically be used?

Single Answer MCQ
Q-00094706
View explanation
Q54.

Which of the following is true about the seek() method?

Single Answer MCQ
Q-00094707
View explanation
Q55.

If the file pointer is at the end of the file, what will file_object.seek(-1, 2) do?

Single Answer MCQ
Q-00094708
View explanation
Q56.

In what scenario would using tell() after seek() provide different results?

Single Answer MCQ
Q-00094709
View explanation
Q57.

What happens if you use the seek() method to position the pointer beyond the file size?

Single Answer MCQ
Q-00094710
View explanation
Q58.

What is the purpose of the 'open()' function in file handling?

Single Answer MCQ
Q-00094711
View explanation
Q59.

Which mode should be used with 'open()' to append data to an existing file?

Single Answer MCQ
Q-00094712
View explanation
Q60.

What does the 'readline()' function do?

Single Answer MCQ
Q-00094713
View explanation
Q61.

If a file is opened using 'open('file.txt', 'w')', what happens if 'file.txt' already exists?

Single Answer MCQ
Q-00094714
View explanation
Q62.

In Python, what function would you use to move to the beginning of a file?

Single Answer MCQ
Q-00094715
View explanation
Q63.

What is the effect of calling 'file.close()'?

Single Answer MCQ
Q-00094716
View explanation
Q64.

How can you read all lines from a text file with a single command?

Single Answer MCQ
Q-00094717
View explanation
Q65.

What happens when you use 'open('file.txt', 'x')'?

Single Answer MCQ
Q-00094718
View explanation
Q66.

Which of the following is a valid way to write 'Hello World' to a file named 'greet.txt'?

Single Answer MCQ
Q-00094719
View explanation
Q67.

In Python, how can you check the current position of the file cursor?

Single Answer MCQ
Q-00094720
View explanation
Q68.

Which method is used to reset the file pointer to the end of the currently opened file?

Single Answer MCQ
Q-00094721
View explanation
Q69.

What happens to the data in a file if you open it in both 'r+' and 'w+' mode consecutively?

Single Answer MCQ
Q-00094722
View explanation
Q70.

What is the default file mode when using 'open()'?

Single Answer MCQ
Q-00094723
View explanation
Q71.

When reading from a binary file, which method should be used?

Single Answer MCQ
Q-00094724
View explanation
Q72.

Which function would you use to ensure your file is closed automatically after operations are completed?

Single Answer MCQ
Q-00094725
View explanation
Q73.

What does the pickle module in Python primarily do?

Single Answer MCQ
Q-00094741
View explanation
Q74.

Which two methods are primarily used in the pickle module?

Single Answer MCQ
Q-00094742
View explanation
Q75.

When using the dump() method, how should the file be opened?

Single Answer MCQ
Q-00094743
View explanation
Q76.

What is the result of the load() method?

Single Answer MCQ
Q-00094744
View explanation
Q77.

Which statement about pickling is incorrect?

Single Answer MCQ
Q-00094745
View explanation
Q78.

What do you need to do before using the pickle module?

Single Answer MCQ
Q-00094746
View explanation
Q79.

What is the purpose of binary mode in files when using pickle?

Single Answer MCQ
Q-00094747
View explanation
Q80.

In the context of the pickle module, what does 'serializing' mean?

Single Answer MCQ
Q-00094748
View explanation
Q81.

When unpickling, which file mode must be used?

Single Answer MCQ
Q-00094749
View explanation
Q82.

Which of the following is a correct syntax for the load() method?

Single Answer MCQ
Q-00094750
View explanation
Q83.

Pickling can be described as which of the following processes?

Single Answer MCQ
Q-00094751
View explanation
Q84.

Which of the following is NOT a valid use case for the pickle module?

Single Answer MCQ
Q-00094752
View explanation
Q85.

Which of the following will occur if you try to load from a file that has not been properly pickled?

Single Answer MCQ
Q-00094753
View explanation
Q86.

What will the following code output? 'print(pickle.load(open("mybinary.dat", "rb")))'

Single Answer MCQ
Q-00094754
View explanation
Q87.

What function is used to open a file in Python?

Single Answer MCQ
Q-00103602
View explanation
Q88.

Which mode should you use for creating a new file or overwriting an existing file?

Single Answer MCQ
Q-00103603
View explanation
Q89.

What does the 'rb' mode do when opening a file?

Single Answer MCQ
Q-00103604
View explanation
Q90.

What will happen if you try to open a file in write mode if it doesn't exist?

Single Answer MCQ
Q-00103605
View explanation
Q91.

Which attribute would you check to determine if a file is closed?

Single Answer MCQ
Q-00103606
View explanation
Q92.

If you open a file with 'a+' mode, where does the file pointer start?

Single Answer MCQ
Q-00103607
View explanation
Q93.

What happens to existing data in a file when it is opened in write mode (w)?

Single Answer MCQ
Q-00103608
View explanation
Q94.

Which mode would you use if you want to read a file and also add to it without losing the current data?

Single Answer MCQ
Q-00103609
View explanation
Q95.

When using the open() function, what is the purpose of the file_object variable?

Single Answer MCQ
Q-00103610
View explanation
Q96.

Which method is used to close a file in Python?

Single Answer MCQ
Q-00103611
View explanation
Q97.

What will the statement `file_object= open('data.txt', 'a')` do if 'data.txt' exists?

Single Answer MCQ
Q-00103612
View explanation
Q98.

Which of the following correctly lists access modes for a file in Python?

Single Answer MCQ
Q-00103613
View explanation
Q99.

What indicates the end of a line in a text file in Python?

Single Answer MCQ
Q-00103614
View explanation
Q100.

Which of the following describes the correct behavior when attempting to open a non-existent file in read mode?

Single Answer MCQ
Q-00103615
View explanation
Q101.

What does the open() function return upon successful execution?

Single Answer MCQ
Q-00103616
View explanation
Q102.

Which mode is used to open a file for reading in Python?

Single Answer MCQ
Q-00103617
View explanation
Q103.

What does the read() method return when called without an argument?

Single Answer MCQ
Q-00103618
View explanation
Q104.

What must you ensure before reading from a file in Python?

Single Answer MCQ
Q-00103619
View explanation
Q105.

Which character indicates the end of a line in Python text files?

Single Answer MCQ
Q-00103620
View explanation
Q106.

What happens if you try to read from a file opened in 'w' mode?

Single Answer MCQ
Q-00103621
View explanation
Q107.

Which method would you use to read multiple lines from a text file at once?

Single Answer MCQ
Q-00103622
View explanation
Q108.

If you want to read only the first 10 characters from a text file, which method would you use?

Single Answer MCQ
Q-00103623
View explanation
Q109.

Which of the following correctly closes a file in Python?

Single Answer MCQ
Q-00103624
View explanation
Q110.

Which method would you use to read a specific line from a file in a loop context?

Single Answer MCQ
Q-00103625
View explanation
Q111.

What will the following code output: 'print(file_object.read(5))' if the file content is 'Hello World!'?

Single Answer MCQ
Q-00103626
View explanation
Q112.

How can you prevent modifying a file while reading it in Python?

Single Answer MCQ
Q-00103627
View explanation
Q113.

To handle file reading errors, which block can be used?

Single Answer MCQ
Q-00103628
View explanation
Q114.

When is the __iter__ method called while reading from a file?

Single Answer MCQ
Q-00103629
View explanation
Q115.

What is a common issue when reading a text file with a different encoding?

Single Answer MCQ
Q-00103630
View explanation
Learn Better On The App
Gamified progress

Learning That Feels Rewarding

Earn XP, unlock badges, and turn revision into a habit that feels motivating.

XP and badges
Higher engagement

Faster access to practice, revision, and daily study flow.

Edzy mobile app preview