0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Python_mathライブラリで使用頻度が高い標準メソッド10選

Posted at

Python_mathライブラリで使用頻度が高い標準メソッド10選

  • 用途: 数値計算、数学的操作。
  • 例: math.sqrt, math.pow, math.sin
import math

使用率が高いメソッド10選

  1. math.sqrt(x): 数値の平方根を返します。

    print(math.sqrt(16))
    
  2. math.pow(x, y): xのy乗を計算します。

    print(math.pow(2, 3))
    
  3. math.factorial(x): 数値xの階乗を計算します。

    print(math.factorial(5))
    
  4. math.gcd(x, y): 2つの数値の最大公約数を返します。

    print(math.gcd(48, 18))
    
  5. math.fabs(x): 数値の絶対値を浮動小数点で返します。

    print(math.fabs(-7.5))
    
  6. math.ceil(x): 数値xを超えない最小の整数を返します(切り上げ)。

    print(math.ceil(2.3))
    
  7. math.floor(x): 数値x未満の最大の整数を返します(切り捨て)。

    print(math.floor(2.7))
    
  8. math.sin(x): 角度x(ラジアン)の正弦値を返します。

    print(math.sin(math.pi / 2))
    
  9. math.log(x, base=e): 指定された底(base)におけるxの対数を返します。

    print(math.log(100, 10))
    
  10. math.isclose(a, b, rel_tol=1e-9, abs_tol=0.0): 2つの数値が指定された許容範囲内で等しいかを判定します。

    print(math.isclose(1.000001, 1.0, rel_tol=1e-6))
    
    
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?