How to Use Pi in Python?

Overview
Pi in mathematics is a constant value equal to 3.141592653589793 that is used to represent the ratio of the circumference of a circle to its diameter. Pi being an irrational number, is usually represented as an approximation value since the decimal representation of the value doesn't end.
Transform Your Career
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
Introduction to Pi in Python
Python provides libraries, methods, and modules to find the value of pi. To calculate the value of pi we will use
- math.pi
- NumPy
- math.radians
Using Math.pi
math is an inbuilt Python library that imports math.pi and prints the required value of pi.
Output:
Using NumPy for Pi
numpy.pi is a method to calculate the value of pi using NumPy.
Output:
Access Pi (π) Using Math.radians
We can also find the value of pi using the function radians() from the math library provided by Python. Passing the value for radian as 180, the value of pi is returned.
Output:
Example: Calculating the Circumference of a Circle
Output:
Conclusion
- To find the value of pi using Python we use an inbuilt python library math that imports math.pi to calculate the value of pi.
- We can also use numpy.pi to find the value of pi.
- Using the function radian() with 180 passed as an argument also returns the value of pi in Python programming language.