Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Python - math.prod() method
Next article icon

Python – math.dist() method

Last Updated : 23 Jan, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report

Math module in Python contains a number of mathematical operations, which can be performed with ease using the module. math.dist() method in Python is used to the Euclidean distance between two points p and q, each given as a sequence (or iterable) of coordinates. The two points must have the same dimension.
This method is new in Python version 3.8.

Syntax: math.dist(p, q)

Parameters:
p: A sequence or iterable of coordinates representing first point
q: A sequence or iterable of coordinates representing second point

Returns: the calculated Euclidean distance between the given points.

Code #1: Use of math.dist() method




# Python Program to explain math.dist() method
  
# Importing math module
import math
  
# One dimensional Point
  
# Coordinate of Point P
P = 3
  
# Coordinates of point Q
Q = -8
  
# Calculate the Euclidean distance 
# between points P and Q
eDistance = math.dist([P], [Q])
print(eDistance)
 
 
Output:
  11.0  

Code #2:




# Python Program to explain math.dist() method
  
# Importing math module
import math
  
# Two dimensional Point
  
# Coordinates of Point P
Px = 3 
Py = 7
  
# Coordinates of point Q
Qx = -5
Qy = -9
  
# Calculate the Euclidean distance 
# between points P and Q
eDistance = math.dist([Px, Py], [Qx, Qy])
print(eDistance)
  
  
# Three-dimensional point
  
# Coordinates of Point P
P = [3, 6, 9]
  
# Coordinates of point Q
Q = [1, 0, -2] 
  
# Calculate the Euclidean distance 
# between points P and Q
eDistance = math.dist(P, Q)
print(eDistance)
 
 
Output:
  17.88854381999832  12.688577540449518  

Code #3:




# Python Program to explain math.dist() method
  
# Importing math module
import math
  
# n-dimensional Point
  
# Coordinates of Point P
P = [3, 9, 7, 2, 4, 5] 
  
# Coordinates of point Q
Q = [-5, -3, -9, 0, 6, 2]
  
# Calculate the Euclidean distance 
# between points P and Q
eDistance = math.dist(P, Q)
print(eDistance)
  
# Dimension of both points 
# should be the same 
 
 
Output:
  21.93171219946131  

Reference: Python math library



Next Article
Python - math.prod() method

I

ihritik
Improve
Article Tags :
  • Python
  • Python math-library
  • Python math-library-functions
Practice Tags :
  • python

Similar Reads

  • Python | math.isqrt() method
    Math module in Python contains a number of mathematical operations, which can be performed with ease using the module. math.isqrt() method in Python is used to get the integer square root of the given non-negative integer value n. This method returns the floor value of the exact square root of n or
    2 min read
  • Python List methods
    Python list methods are built-in functions that allow us to perform various operations on lists, such as adding, removing, or modifying elements. In this article, we’ll explore all Python list methods with a simple example. List MethodsLet's look at different list methods in Python: append(): Adds a
    3 min read
  • Python | Decimal max() method
    Decimal#max() : max() is a Decimal class method which compares the two Decimal values and return the max of two. Syntax: Decimal.max() Parameter: Decimal values Return: the max of two. Code #1 : Example for max() method # Python Program explaining # max() method # loading decimal library from decima
    2 min read
  • Python - math.prod() method
    Math module in Python contains a number of mathematical operations, which can be performed with ease using the module. math.prod() method in Python is used to calculate the product of all the elements present in the given iterable. Most of the built-in containers in Python like list, tuple are itera
    2 min read
  • Python | Decimal ln() method
    Decimal#ln() : ln() is a Decimal class method which returns the natural (base e) logarithm of the Decimal value. Syntax: Decimal.ln() Parameter: Decimal values Return: the natural (base e) logarithm of the Decimal value. Code #1 : Example for ln() method # Python Program explaining # ln() method # l
    2 min read
  • Python | cmath.sqrt() method
    With the help of cmath.sqrt() method, we can find the value of square root any number by passing it to cmath.sqrt() method. Syntax : cmath.sqrt(value) Return : Return the square root of any value. Example #1 : In this example we can see that by using cmath.sqrt() method, we are able to get the value
    1 min read
  • Python | Decimal min() method
    Decimal#min() : min() is a Decimal class method which compares the two Decimal values and return the min of two. Syntax: Decimal.min() Parameter: Decimal values Return: the min of two. Code #1 : Example for min() method # Python Program explaining # min() method # loading decimal library from decima
    2 min read
  • Python | Decimal adjusted() method
    Decimal#adjusted() : adjusted() is a Decimal class method which returns the adjusted exponent after shifting out the coefficient’s rightmost digits until only the lead digit remains Syntax: Decimal.adjusted() Parameter: Decimal values Return: the adjusted exponent after shifting out the coefficient’
    2 min read
  • Python | Decimal exp() method
    Decimal#exp() : exp() is a Decimal class method which returns the value of the (natural) exponential function e**x at the given number Syntax: Decimal.exp() Parameter: Decimal values Return: the value of the (natural) exponential function e**x at the given number Code #1 : Example for exp() method #
    2 min read
  • Python math library | exp() method
    Python has math library and has many functions regarding it. One such function is exp(). This method is used to calculate the power of e i.e. e^y or we can say exponential of y. The value of e is approximately equal to 2.71828….. Syntax : math.exp(y) Parameters : y [Required] - It is any valid pytho
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences