Easy Tutorial
❮ Python Os Pipe Ref Math Prod ❯

Python math.dist() Method

Python math Module

The math.dist(p, q) method in Python returns the Euclidean distance between points p and q, given as coordinate sequences (or iterables). Both points must have the same dimensions.

The parameters must be positive integers.

Python version: 3.8

Syntax

The syntax for the math.dist() method is as follows:

math.dist(p, q)

Parameter Description:

Return Value

Returns a float value representing the Euclidean distance between p and q.

Example

The following example calculates the Euclidean distance between two points:

Example

# Import math package
import math

p = [3]
q = [1]

# Calculate Euclidean distance
print(math.dist(p, q))

p = [3, 3]
q = [6, 12]

# Calculate Euclidean distance
print(math.dist(p, q))

Output result:

2.0
9.486832980505138

Python math Module

❮ Python Os Pipe Ref Math Prod ❯