math.dist()
from the math module in Python is used to calculate the Euclidean distance between two points, p
and q
. To calculate the distance between these points, p
and q
should have the same dimensions.
math.dist(p,q)
Both values should be a single integer or a list of integer values.
p
: first argumentq
: second argumentfloat-value
: This method will return the Euclidean distance between p
and q
.
This math.dist()
method helps to calculate Euclidean distance. Therefore, in line 7 we calculate it using p = [5]
and q = [3]
. In line 12, however, we use a list of integer values as arguments, i.e., p = [5, 5]
, q = [3, 6]
# Import math Libraryimport math# single integer valuesp = [5]q = [3]# Calculate Euclidean distanceprint (math.dist(p, q))# -------- p,q as List---------p = [5, 5]q = [3, 6]# Calculate Euclidean distanceprint (math.dist(p, q))