Data file handling in python class 12 you get important Questions for File Handling – Computer Science with Python. For answers check out these posts:
Data file handling in python class 12 Objective type questions:
Fill in the blanks
- A collection of bytes stored in computer’s secondary memory is known as _______.
- ___________ is a process of storing data into files and allows to performs various tasks such as read, write, append, search and modify in files.
- The transfer of data from program to memory (RAM) to permanent storage device (hard disk) and vice versa are known as __________.
- A _______ is a file that stores data in a specific format on secondary storage devices.
- In ___________ files each line terminates with EOL or ‘\n’ or carriage return, or ‘\r\n’.
- To open file data.txt for reading, open function will be written as f = _______.
- To open file data.txt for writing, open function will be written as f = ________.
- In f=open(“data.txt”,”w”), f refers to ________.
- To close file in a program _______ function is used.
- A __________ function reads first 15 characters of file.
- A _________ function reads most n bytes and returns the read bytes in the form of a string.
- A _________ function reads all lines from the file.
- A _______ function requires a string (File_Path) as parameter to write in the file.
- A _____ function requires a sequence of lines, lists, tuples etc. to write data into file.
- To add data into an existing file ________ mode is used.
- A _________ function is used to write contents of buffer onto storage.
- A text file stores data in _________ or _________ form.
- A ___________ is plain text file which contains list of data in tabular form.
- You can create a file using _________ function in python.
- A __________ symbol is used to perform reading as well as writing on files in python.
Find answer below for data file handling in python class 12.
- File Handling
- I/O Operations
- Data file
- Text File
- File handle or File Object
- ASCII, UNICODE
Data file handling in python class 12 – MCQs
1 Every file has its own identity associated with it. Which is known as –
d. file type
2 Which of the following is not a known file type?
3. In f=open(“data.txt”, “r”), r refers to __________.
a. File handle
b. File object
c. File Mode
4. EOL stands for
a. End Of Line
b. End Of List
c. End of Lines
d. End Of Location
5. 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
6. 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
7. Which of the following is nor a proper file access mode?
8. To read 4th line from text file, which of the following statement is true?
a. dt = f.readlines();print(dt)
b. dt=f.read(4) ;print(dt)
d. All of these
9 Which of the following function flushes the files implicitly?
10. Which of the following functions flushes the data before closing the file?
data file handling in python class 12 – Short answer questions/ Conceptual Questions
Please refer notes section for the answers on Data file handling in python class 12.
1 What do you mean file? What do you mean by file handling?
2 Explain open() function with its syntax in detail.
3 Does python create a itself if the file doesn’t exist in the memory? Illustrate your answer with example.
Answer: Python will creates a file automatically when open function is used with write mode.
f=open("data.txt","w") f.write("Hello\nHow are you?") f.close()
4 Write a statement to create data.txt file with following text.
Python file handling is very interesting and useful.
This is a text file created through python.
5 List out the basic file modes available in python.
6 Compare text files, binary files and csv files and write pros and cons of each of them.
data file handling in python class 12 – Application Based questions
The following section contains few case study based questions for Data file handling in python class 12.
1 Write a python programs to create and read city.txt file in one go and print the contents in the output screen.
# Creating file with open() function f=open("city.txt","w") f.write("My city is very clean city.") f.close() # Reading contents from city.txt file f=open("city.txt","r") dt = f.read() print(dt) f.close()
2 Consider following lines for the file friends.txt and predict the output:
Friends are crazy, Friends are naughty ! Friends are honest, Friends are best ! Friends are like keygen, friends are like license key ! We are nothing without friends, Life is not possible without friends !
f = open("friends.txt") l = f.readline() l2 = f.readline(18) ch3=f.read(10) print(l2) print(ch3) print(f.readline()) f.close()
Friends are honest
are best !
In line no. 2, f.readline() function reads first line and stores the output string in l but not printed in the code, then it moves the pointer to next line in the file. In next statement we have f.readline(18) which reads next 18 characters and place the cursor at the next position i.e. comma (,) , in next statement f.read(10) reads next 10 characters and stores in ch3 variable and then cursor moves to the next position and at last f.readline() function print() the entire line.
3 Write a function count_lines() to count and display the total number of lines from the file. Consider above file – friends.txt.
def count_lines(): f = open("friends.txt") cnt =0 for lines in f: cnt+=1 print("no. of lines:",cnt) f.close()
4 Write a function display_oddLines() to display odd number lines from the text file. Consider above file – friends.txt.
def display_oddLines(): f = open("friends.txt") cnt =0 for lines in f: cnt+=1 if cnt%2!=0: print(lines) f.close()
5 Write a function cust_data() to ask user to enter their names and age to store data in customer.txt file.
def cust_data(): name = input("Enter customer name:") age=int(input("Enter customer age:")) data = str([name,age]) f = open("customer.txt","w") f.write(data) f.close()
Thank you very much for visiting our website and reading the article data file handling in python class 12.
Click here to read data file handling in python class 12 notes for text files.
Kindly share the contents to help the community and your friends. Share your views in the comment section about this article.
Feel free to ask your doubts in the comments section as well.
If you are looking for Sumita Arora textbook solutions on Data file handling in python class 12 click here.
If you need more questions and assignments let us know in the comments on the topic Data file handling in python class 12.
Download the contents in pdf file.