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
math.exp(x)- Returns e raised to the power of x.Example:
pythonimport math x = math.exp(2) print(x) # Output: 7.38905609893065
math.expm1(x)- Returns ex - 1.Example:
pythonimport math x = math.expm1(1) print(x) # Output: 1.718281828459045
math.pow(x, y)- Returns x raised to the power of y.Example:
pythonimport math x = math.pow(3, 2) print(x) # Output: 9.0
math.sqrt(x)- Returns the square root of x.Example:
pythonimport math x = math.sqrt(16) print(x) # Output: 4.0
Try It Yourself: Fun Exercises
- Calculate Exponential Growth:
- Use
math.exp()to calculate the exponential growth of a quantity over time.
- Use
- Explore Power Calculations:
- Experiment with
math.pow()to calculate different powers, like 5^3 and 2^8.
- Experiment with
- Find Square Roots:
- Use
math.sqrt()to find the square root of various numbers and see how it changes.
- Use
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!