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:

    python
    result = base ** exponent
    
    • base is the number you want to raise.
    • exponent is the power you want to raise the base to.
    • result will store the outcome.

Examples and Exercises:

  1. Exponentiation of Integers:

    python
    a = 14
    b = 5
    result = a ** b
    print('Result:', result)  
    • Output: Result: 537824
  2. Exponentiation with a Negative Exponent:

    • You can also use negative exponents.
    python
    a = 14
    b = -5
    result = a ** b
    print('Result:', result)  
    • Output: Result: 1.8593443208187064e-06
  3. Exponentiation of Floating Point Numbers:

    • You can raise floating point numbers to a power too.
    python
    a = 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!