Exponentiation
What Is the Exponentiation Operator?
- The exponentiation operator
**in Python is used to raise a number (the base) to the power of another number (the exponent).
How to Use It:
The basic way to use the exponentiation operator is:
pythonresult = base ** exponentbaseis the number you want to raise.exponentis the power you want to raise the base to.resultwill store the outcome.
Examples and Exercises:
Exponentiation of Integers:
pythona = 14 b = 5 result = a ** b print('Result:', result)- Output:
Result: 537824
- Output:
Exponentiation with a Negative Exponent:
- You can also use negative exponents.
pythona = 14 b = -5 result = a ** b print('Result:', result)- Output:
Result: 1.8593443208187064e-06
Exponentiation of Floating Point Numbers:
- You can raise floating point numbers to a power too.
pythona = 3.14 b = 4.1 result = a ** b print('Result:', result)- Output:
Result: 108.99625018584567
Summary:
- The exponentiation operator
**in Python allows you to raise a base number to the power of an exponent. It can be used with both integers and floating point numbers. Try the examples to see how it works!