Python Beatles () function
deskripsi
fabs () metode mengembalikan jumlah nilai absolut, seperti math.fabs (-10) mengembalikan 10,0.
tatabahasa
Berikut ini adalah Beatles sintaks () metode:
import math math.fabs( x )
Catatan: Beatles () tidak langsung dapat diakses, Anda perlu mengimpor modul matematika, memanggil metode melalui objek statis.
parameter
- x - ekspresi numerik.
Kembali Nilai
Mengembalikan nilai absolut dari nomor tersebut.contoh
Berikut ini menunjukkan contoh penggunaan Beatles () metode:
#!/usr/bin/python # -*- coding: UTF-8 -*- import math # 导入数学模块 print "math.fabs(-45.17) : ", math.fabs(-45.17) print "math.fabs(100.12) : ", math.fabs(100.12) print "math.fabs(100.72) : ", math.fabs(100.72) print "math.fabs(119L) : ", math.fabs(119L) print "math.fabs(math.pi) : ", math.fabs(math.pi)
Setelah menjalankan contoh di atas output:
math.fabs(-45.17) : 45.17 math.fabs(100.12) : 100.12 math.fabs(100.72) : 100.72 math.fabs(119L) : 119.0 math.fabs(math.pi) : 3.14159265359