How to find exponent of a number in Python?

0 votes
I am new to Python. I wish to write a function in python that calculates a square or a cube or any other power of a number? How to do it ?
Jul 2 in Python by Neel
• 3,010 points
28 views

1 answer to this question.

0 votes
Yes you can do it using the math library in Python

import math
x = math.pow(2,3) # x = 2 to the power of 3
print(x)

You can include the above code in a function and then call the function.
answered Jul 2 by Arvind
• 2,960 points

Related Questions In Python

0 votes
2 answers

How to calculate square root of a number in python?

calculate square root in python >>> import math ...READ MORE

answered Apr 2 in Python by anonymous
247 views
–1 vote
2 answers

How to find the size of a string in Python?

following way to find length of string  x ...READ MORE

answered Mar 29 in Python by rajesh
• 1,210 points
101 views
0 votes
2 answers
0 votes
1 answer
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 332 views
0 votes
2 answers

How to check whether a string contains alphabets or number in Python?

By using isAlpha () to check whether ...READ MORE

answered Jul 13 in Python by Sheik janibasha
70 views
0 votes
1 answer

How to find the type of variable in Python?

i=277 type(i) # int i = 2.56j type(i) # complex i ...READ MORE

answered Jul 16 in Python by Arvind
• 2,960 points
19 views