English

When are the following built-in exceptions raised? Give examples to support your answer. ImportError - Computer Science (Python)

Advertisements
Advertisements

Question

When are the following built-in exceptions raised? Give examples to support your answer.

ImportError

Short Note

Solution

It is raised when the requested module definition is not found.

 >>> import maths
       Traceback (most recent call last):
         File "", line 1, in 
           import maths
       ModuleNotFoundError: No module named 'maths'
>>> import randoms
       Traceback (most recent call last):
         File "", line 1, in 
           import randoms
       ModuleNotFoundError: No module named 'randoms'    

import maths #Raise an ImportError, due to maths module does not exists.

shaalaa.com
Built-in Exceptions
  Is there an error in this question or solution?
Chapter 1: Exception Handling in Python - Exercise [Page 17]

APPEARS IN

NCERT Computer Science [English] Class 12
Chapter 1 Exception Handling in Python
Exercise | Q 2. a) | Page 17
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×