pythonで数値の二乗、累乗を求める方法/pow関数の使い方

dandelion IT

pow関数ではふたつの値を指定することで、xのy乗を求めることができます。

スポンサーリンク

pow関数

python pow1
pow関数を使用するには、先に組み込みモジュールmathimportする必要があります。
#python
import math
p = math.pow(5,3)
print(p)
mathモジュールをimportできたら、math.powの引数にxとyを指定することで、xのy乗を求めることができます。
python pow2
この場合5の3乗を求めているので、戻り値は125となります。
Python操作方法、関数・メソッドリファレンス
使用用途別にまとめたPythonリファレンスページです。 初期準備、基本概念 ダウンロード、インストール、起動 ShellとEditor、保存、実行 保存したPythonの起動 コメント、docstring、行またぎ コメント、...

コメント

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny