Computer Science Class XII Python File Handling Test Series Part 2

 

Computer Science Class XII Python File Handling Test Series Part 2

Q1. f = open("data.txt")

  1. Identify name of file.
  2. Identify name of function.
  3. What if 'f' in above code?
  4. The above statement will __________ file in ________ mode.

Q2. What is the default mode of opening a file?


Q3. Write a statement in python to open a file named "data.txt" stored in folder "content" in D drive.


Q4. What error is returned by following statement, if file "try.txt" does not exist?
                f = open("try.txt")

Q5. Name the three modes in which file can be opened in python.


Q6. What is the purpose of 'r' as prefix in the given statement?
        f = open(r, "d:\color\flower.txt")


Q7. What do you mean by file object in python?


Q8. Another name of file object is _______


Q9. Write the symbols used in place of 'x' to open text file for the following operations.
                    f = open("name.txt", 'x')
  1. Read Only
  2. Write only
  3. Read and Write
  4. Write and Read

Q10. Write the symbols used in place of 'x' to open binary file for the following operations.
                    f = open("name.dat", 'x')
  1. Read Only
  2. Write only
  3. Read and Write
  4. Write and Read


 SOLUTIONS

Q1. f = open("data.txt")

  1. Identify name of file.
  2. Identify name of function.
  3. What if 'f' in above code?
  4. The above statement will __________ file in ________ mode.
Ans. 
  1. data.txt
  2. open()
  3. file object
  4. open, read
Q2. What is the default mode of opening a file?
Ans. read mode

Q3. Write a statement in python to open a file named "data.txt" stored in folder "content" in D drive.
Ans. f = open("d:\\content\\data.txt")

                    OR

        f = open(r, "d:\content\data.txt")

Q4. What error is returned by following statement, if file "try.txt" does not exist?
                f = open("try.txt")
Ans. FileNotFoundError

Q5. Name the three modes in which file can be opened in python.
Ans. Read, Write and Append

Q6. What is the purpose of 'r' as prefix in the given statement?
        f = open(r, "d:\color\flower.txt")
Ans. 'r' makes the string as raw string, means there is no special character in string.

Q7. What do you mean by file object in python?
Ans. File object is reference to a file. It is used to read and write data to a file.

Q8. Another name of file object is _______
Ans. File Handle

Q9. Write the symbols used in text file mode for the following operations.
  1. Read Only
  2. Write only
  3. Read and Write
  4. Write and Read
Ans. 
  1. r
  2. w
  3. r+
  4. w+
Q10. Write the symbols used in binary file mode for the following operations.
  1. Read Only
  2. Write only
  3. Read and Write
  4. Write and Read
Ans.
  1. rb
  2. wb
  3. rb+
  4. wb+

No comments:

Post a Comment

Most Recently Published

File Handling Test 6

 File Handling Test 6 Q1 . Do we need to use the close() function when we use 'with' statement to open a file? Q2. Which mode you wi...

CS - IP Assignment/Worksheet