Explain the difference with regard to the namespaces they cr

Explain the difference (with regard to the namespaces they create) among the following three ways to import the math module: import math from math import* import math as ma

Solution

The \"advantage\" of from xyz import * as opposed to other forms of import is that it imports everything (well, almost... [see (a) below] everything) from the designated module under the current module. This allows using the various objects (variables, classes, methods...) from the imported module without prefixing them with the module\'s name. For example

This practice (of importing * into the current namespace) is however discouraged because it it

Typically we therefore limit this import * practice to ad-hoc tests and the like, and instead:

explicitly import a few objects only

or import the module under its own namespace (or an alias thereof, in particular if this is a long name, and the program references its objects many times)

Hope it will help you

 Explain the difference (with regard to the namespaces they create) among the following three ways to import the math module: import math from math import* impo

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site