पायथन गणित। isclose () विधि
उदाहरण
जांचें कि दो मान एक दूसरे के करीब हैं या नहीं:
#Import math Library
import math
#compare the closeness of two values
print(math.isclose(1.233, 1.4566))
print(math.isclose(1.233, 1.233))
print(math.isclose(1.233, 1.24))
print(math.isclose(1.233, 1.233000001))
परिभाषा और उपयोग
विधि यह math.isclose()
जांचती है कि दो मान एक दूसरे के करीब हैं या नहीं। यदि मान करीब हैं, तो सही है, अन्यथा गलत है।
यह विधि एक सापेक्ष या पूर्ण सहिष्णुता का उपयोग करती है, यह देखने के लिए कि क्या मान करीब हैं।
युक्ति: यह मानों की तुलना करने के लिए निम्न सूत्र का उपयोग करता है: abs(ab) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)
वाक्य - विन्यास
math.isclose(a, b, rel_tol, abs_tol)
पैरामीटर मान
Parameter | Description |
---|---|
a | Required. The first value to check for closeness |
b | Required. The second value to check for closeness |
rel_tol = value | Optional. The relative tolerance. It is the maximum allowed difference between value a and b. Default value is 1e-09 |
abs_tol = value | Optional. The minimum absolute tolerance. It is used to compare values near 0. The value must be at least 0 |
टेक्निकल डिटेल
प्रतिलाभ की मात्रा: | एक bool मूल्य। True यदि मान करीब हैं, अन्यथाFalse |
---|---|
पायथन संस्करण: | 3.5 |
और ज्यादा उदाहरण
उदाहरण
पूर्ण सहिष्णुता का प्रयोग करें:
#Import math Library
import math
#compare the closeness of two
values
print(math.isclose(8.005, 8.450, abs_tol = 0.4))
print(math.isclose(8.005, 8.450, abs_tol = 0.5))