GoConqr has a new look! Let us know what you think.

Module 14 of 24 · Text

Arithmetic operators: exponentiation

David Khieu

Arithmetic operators: exponentiation 

a ** (double asterisk) sign is an exponentiation (power) operator. Its left argument is the  base, its right, the exponent.

Classical mathematics prefers notation with superscripts, just like this: 2^3. Pure text editors don't accept that, so Python uses ** instead, e.g. 2**3

Take a look at our examples in the editor window. 

print(2 ** 3)
print(2 ** 3.)
print(2. ** 3)
print(2. ** 3.)

Note: we've surrounded the double asterisks with spaces in our examples. It's not compulsory, but it improves the readability of the code. 

The examples show a very important feature of virtually all Python  Numerical Operators.

Run the code and look carefully at the results it products. Can you see any regularity here?

Remember: It's possible to formulate the following rules based on this result: 

  • when both ** arguments are integers, the result is an integer, too
  • when at least one ** argument is a float, the result is a float. too

This is an important distinction to remember.

Instructions

You must submit an attempt for this quiz to progress. You can submit it after the last question.

Go to the chosen module

Feedback

What is it about?

What do you think of the new look?

How do you like it?