KnowledgeBoat Logo

Computer Science

Create module tempConversion.py as given in Fig. 4.2 in the chapter. If you invoke the module with two different types of import statements, how would the function call statement for imported module's functions be affected ?

Create module tempConversion.py as given in Fig. 4.2 in the chapter. If you invoke the module with two different types of import statements, how would the function call statement for imported module's functions be affected ? Python Computer Science Sumita Arora Solutions CBSE Class 12

Python Libraries

6 Likes

Answer

If we invoke the tempConversion module with two different types of import statements (import tempConversion and from tempConversion import *), the way we call the module's functions will be affected as follows:

1. import tempConversion — This imports the entire module in a new namespace setup with the same name as that of the module tempConversion. To call the module's functions, we need to use the dot notation tempConversion.<function_name>.
For example:

import tempConversion
tempConversion.to_centigrade(32) 
tempConversion.to_fahrenheit(0) 

2. from tempConversion import * — This imports all objects (functions, variables, etc.) from the module into the current namespace. This approach imports all objects directly into the current namespace, so we can call the module's functions without using the module name.
For example:

from tempConversion import *
to_centigrade(32)
to_fahrenheit(0)   

Answered By

2 Likes


Related Questions