計算
コマンドプロンプトを起動
C:\Users\user>python
Python 3.9.9 (tags/v3.9.9:ccb0e6a, Nov 15 2021, 18:08:50) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
演算
>>> 5-2
3
>>> 5 + 6
11
>>> 50 - 5 * 6
20
>>> (50 -5) * 6
270
>>> 8 / 5
1.6
>>> type(1)
<class 'int'>
>>> type(1.6)
<class 'float'>
>>> 0.6
0.6
浮動小数点型の場合、「0」ゼロは省略可能 >>> .6 0.6
> 17 / 3
5.666666666666667
>>> 17 // 3
5
>>> 5 * 5
25
>>> 5 ** 2
25
>>> 5 * 5 * 5 * 5 * 5
3125
>>> 5 ** 5
3125
変数
>>> x = 5
>>> x
5
>>> y = 10
>>> y
10
>>> x * y
50
>>> pie = 3.1415926535
>>> pie
3.1415926535
>>> round(pie)
3
>>> round(pie, 2)
3.14
> exit()
数学関数
import math
result = math.sqrt(25)
print(result)
5
y = math.log2(10)
print (y)
3.321928094887362
Help関数
print(help(math))
log2(x, /)
Return the base 2 logarithm of x.
コメント