Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python math.dist() Method

Python math.dist() Method

Python math Module Python math Module

Python math.dist(p, q) The method returns the Euclidean distance between two points p and q, given as a sequence of coordinates (or an iterable). The two points must have the same dimension.

The arguments passed in must be positive integers.

Python version: 3.8

Syntax

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

math.dist(p, q)

Parameter Description:

Return Value

Returns a floating-point value representing the Euclidean distance between p and q.

Example

The following example returns the Euclidean distance between two points:

Example

Import the math package

import

math

p

=

[

3

]

q

=

[

1

]

Compute the Euclidean distance

print

(

math

.

dist

(

p

,

q

)

)

p

=

[

3

,

3

]

q

=

[

6

,

12

]

Compute the Euclidean distance

print

(

math

.

dist

(

p

,

q

)

)

Output result:


2.0
9.486832980505138

Python math Module Python math Module