156k views
2 votes
You are working on a Python script that relies heavily on the cos and sin functions of the math module. As these are the only functions you require, what should you do to import only these functions, rather than the whole math module?

1 Answer

4 votes

Answer:

  1. from math import cos
  2. from math import sin

Step-by-step explanation:

To import only a specific function from a module, we can use a syntax as follows:

  • from module import function_name

Once the specific function imported from the module, we can directly invoke the function in our code as follows:

  • cos(0.5)
  • sin(0.45)

Please note this is not necessary to call the function by preceding the function name with math module (e.g. math.xxx). Hence, this approach also help to reduce the code redundancy.

User Lukas Hinsch
by
5.4k points