To calculate the power of a number in Python, you can use the ** operator or the built-in pow() function.
Here are two examples of code:
# Using the ** operator
num1 = 2
power1 = 3
result1 = num1 ** power1
print("The result of", num1, "raised to the power of", power1, "is", result1)
# Using the pow() function
num2 = 5
power2 = 2
result2 = pow(num2, power2)
print("The result of", num2, "raised to the power of", power2, "is", result2)
In both examples, the variables num and power are set to the base and exponent of the power operation. The result of raising num to the power of power is calculated using either the ** operator or the pow() function, and the result is assigned to the variable result. The result is then printed using the print function.
You can replace the values of num and power with any other numbers to calculate the power of a number using the same code.