Power Functions

What You'll Learn: In this tutorial, you'll discover various power functions available in Python's math module. These functions help you perform calculations involving powers and roots.

Power Functions

  1. math.exp(x) - Returns e raised to the power of x.
    • Example:

      python
      import math
      x = math.exp(2)
      print(x)  # Output: 7.38905609893065
      
  2. math.expm1(x) - Returns ex - 1.
    • Example:

      python
      import math
      x = math.expm1(1)
      print(x)  # Output: 1.718281828459045
      
  3. math.pow(x, y) - Returns x raised to the power of y.
    • Example:

      python
      import math
      x = math.pow(3, 2)
      print(x)  # Output: 9.0
      
  4. math.sqrt(x) - Returns the square root of x.
    • Example:

      python
      import math
      x = math.sqrt(16)
      print(x)  # Output: 4.0
      

Try It Yourself: Fun Exercises

  1. Calculate Exponential Growth:
    • Use math.exp() to calculate the exponential growth of a quantity over time.
  2. Explore Power Calculations:
    • Experiment with math.pow() to calculate different powers, like 5^3 and 2^8.
  3. Find Square Roots:
    • Use math.sqrt() to find the square root of various numbers and see how it changes.

Summary:

In this Python tutorial, we explored various power functions available in the math module. These functions help you perform calculations involving powers and roots. Keep experimenting and have fun with Python!