Important MCQ of Exception and File Handling in Python

Important MCQ of Exception and File Handling in Python

Answer: d
Explanation: There has to be at least one except statement.

a) yes, like except TypeError, SyntaxError [,…]
b) yes, like except [TypeError, SyntaxError]
c) no
d) none of the mentioned

Answer: a
Explanation: Each type of exception can be specified directly. There is no need to put it in a list.

Answer: b
Explanation: It simply evaluates to False and does not raise any exception.

a. Compile time error

b. Run time error

c. Both (a) and (b)

d. None of these

Answer: c. Both (a) and (b)

a. Created

b. Asserted

c. Triggered

d. Raised

Answer: d. Raised

a. NameError

b. ValueError

c. TypeError

d. ZeroDivisonError

Answer: a. NameError

a. TypeError

b. ValueError

c. NameError

d. SyntaxError

Answer: b. ValueError

a. TypeError

b. NameError

c. IOerror

d. IndexError

Answer: b. NameError

a. Program will execute , but will not display anything

b. Program will throw exception when executed

c. Program will not be complied

d. Program will execute successfully

Answer: c. Program will not be complied

A. StandardError
B. ArithmeticError
C. OverflowError
D. Floating PointError

Ans : C

Explanation: OverflowError : Raised when a calculation exceeds maximum limit for a numeric type

a) ImportError
b) ValueError
c) TypeError
d) NameError

Answer: b
Explanation: The snippet of code shown above results in a value error. This is because there is an invalid literal for int() with base 10: ’65.43’.

Answer: a
Explanation: Syntax errors are known as parsing errors. Syntax errors are raised when there is a deviation from the rules of a language. Hence the statement is true.

Answer: a
Explanation: An exception is an object that is raised by a function signaling that an unexpected situation has occurred, that the function itself cannot handle.

a. Using the `global_exception_handler()` function

b. By modifying the global exception settings in the `sys` module

c. By using the `global` keyword

d. There is no way to handle exceptions globally

Answer: B. By modifying the global exception settings in the `sys` module

a. 16

b. 32

c. 64

d. None of these above

Answer: (d) None of these above

Explanation: The maximum possible length of an identifier is not defined in the python language. It can be of any number.

a. Zim Den

b. Guido van Rossum

c. Niene Stom

d Wick van Rossum

Answer: (b) Guido van Rossum

Explanation: Python language was developed by Guido van Rossum in the Netherlands.

a. open()

b. new()

c. Open()

d. None of the above

Answer: a. open()

a. f.readline()

b. f.readlines()

c. f.read()

d. f.line()

Answer: a. f.readline()

a. f,reads()

b. f.read()

c. f.read(all)

d. f.read( * )

Answer: b. f.read()

A. A character string containing the name of the file & the second argument is the mode
B. A character string containing the name of the user & the second argument is the mode
C. A character string containing file pointer & the second argument is the mode
D. None of the mentioned

Ans : A

A. Nothing
B. EOF
C. NULL
D. Depends on compiler

Answer: c. Null

Ans : B

Explanation: It will print only six five character

a. < a >

b. < r+ >

c. < w >

d. < wr+ >

a. open files in write mode

b. it replaces old content with new one in existing file

c. if file does not exists, than produces ‘ FileNotFoundError ‘

d. All are true

Answer: c. if file does not exists, than produces ‘ FileNotFoundError ‘

a. No difference as both are used to read and write content

b. Depends upon type of file

c. In r+ mode cursor is initially placed at the beginning of the file and for w+ cursor is placed at the end

d. In r+ cursor is initially placed at the end of file and for w+ cursor is placed at the beginning

Answer: a. No difference as both are used to read and write content

One thought on “Important MCQ of Exception and File Handling in Python”

Leave a Reply

Your email address will not be published. Required fields are marked *