Data file handling in python class 12 important questions

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

  1. A collection of bytes stored in computer’s secondary memory is known as _______.
  2. ___________ is a process of storing data into files and allows to performs various tasks such as read, write, append, search and modify in files.
  3. The transfer of data from program to memory (RAM) to permanent storage device (hard disk) and vice versa are known as __________.
  4. A _______ is a file that stores data in a specific format on secondary storage devices.
  5. In ___________ files each line terminates with EOL or ‘\n’ or carriage return, or ‘\r\n’.
  6. To open file data.txt for reading, open function will be written as f = _______.
  7. To open file data.txt for writing, open function will be written as f = ________.
  8. In f=open(“data.txt”,”w”), f refers to ________.
  9. To close file in a program _______ function is used.
  10. A __________ function reads first 15 characters of file.
  11. A _________ function reads most n bytes and returns the read bytes in the form of a string.
  12. A _________ function reads all lines from the file.
  13. A _______ function requires a string (File_Path) as parameter to write in the file.
  14. A _____ function requires a sequence of lines, lists, tuples etc. to write data into file.
  15. To add data into an existing file ________ mode is used.
  16. A _________ function is used to write contents of buffer onto storage.
  17. A text file stores data in _________ or _________ form.
  18. A ___________ is plain text file which contains list of data in tabular form.
  19. You can create a file using _________ function in python.
  20. 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.

Answers:

  1. File
  2. File Handling
  3. I/O Operations
  4. Data file
  5. Text File
  6. open(“data.txt”,”r”)
  7. open(“data.txt”,”w”)
  8. File handle or File Object
  9. close
  10. read(15)
  11. readline()
  12. readlines()
  13. write()
  14. writelines()
  15. append
  16. flush()
  17. ASCII, UNICODE
  18. CSV
  19. open()
  20. +

Data file handling in python class 12 – MCQs

1 Every file has its own identity associated with it. Which is known as –

a. icon

b. extension

c. format

d. file type

2 Which of the following is not a known file type?

a. .pdf

b. jpg

c. mp3

d. txp

3. In f=open(“data.txt”, “r”), r refers to __________.

a. File handle

b. File object

c. File Mode

d Buffer

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

Checkout all contents of class XII Computer Science

Click above for complete course contents

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?

a. close

b. read

c. write

d. append

8. To read 4th line from text file, which of the following statement is true?

a. dt = f.readlines();print(dt[3])

b. dt=f.read(4) ;print(dt[3])

c. dt=f.readline(4);print(dt[3])

d. All of these

9 Which of the following function flushes the files implicitly?

a. flush()

b. close()

c. open()

d. fflush()

10. Which of the following functions flushes the data before closing the file?

a. flush()

b. close()

c. open()

d. fflush()

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.

Example:

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.

Answer:

# 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()

Output:

Friends are honest
, Friends
are best !

Explanation:

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.

2 thoughts on “Data file handling in python class 12 important questions”

Comment Your Views

%d bloggers like this: