Pythonで二乗、累乗を求める方法(**の使い方)

IT

Pythonで二乗、三乗などの累乗を求めたい場合は、掛け算の*をひとつ増やしてa**bのように記述します。

スポンサーリンク

**の使い方

まずは*を使った普通の掛け算の場合。
aに2、bに3を代入し、a*bを求めると、
つまり2*3を計算しているので、結果は6が返ります。
#python
a = 2
b = 3
print(a ** b)
今度は*をひとつ増やし、a**bを計算してみると、
2の3乗である8が返ります。後ろの数字が指数になります。
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

モバイルバージョンを終了