Skip to content
  • (+91) 9409548155
  • support@appdividend.com
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
Menu
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
Python

How to Use Pi in Python

  • 08 Aug, 2025
  • Com 0
How to Use pi in Python

The pi is a mathematical constant whose value is 3.14159, which is used in calculations involving circles, spheres, periodic phenomena, and converting from degrees to radians.

Here are two ways to use pi in Python:

  1. Using math.pi
  2. Using numpy.pi

How to Use pi in Python

import numpy as np
import math

print(math.pi)
# Output: 3.141592653589793

print(np.pi)
# Output: 3.141592653589793

Area of a Circle

Area of a circle using pi in Python

The basic application of math.pi is to calculate the area of a circle.

The basic formula for calculating the circle’s area is A = π r².

import math

radius = 5

area = math.pi * radius ** 2

print("Area:", area)

# Output: Area: 78.53981633974483

Converting Degrees to Radians

You can use the pi when you want to convert degrees to radians (radians = degrees * (π/180)).

import math


def degrees_to_radians(degrees):
    return degrees * (math.pi / 180)


print(degrees_to_radians(90))

# Output: 1.5707963267948966 (π/2)

print(math.sin(degrees_to_radians(90)))

# Output: 1.0

Numerical computations with NumPy

Numerical computations with NumPy

Let’s calculate the vectorized circle area calculation.

import numpy as np

array_of_radius = np.array([1, 2, 3])

area = np.pi * array_of_radius ** 2

print("Area:", area)

# Output: [ 3.14159265 12.56637061 28.27433388]

The output is also an array of area values of the respective input radius.

Post Views: 16
Share on:
Krunal Lathiya

With a career spanning over eight years in the field of Computer Science, Krunal’s expertise is rooted in a solid foundation of hands-on experience, complemented by a continuous pursuit of knowledge.

How to Sort a List Alphabetically in Python
JavaScript String toUpperCase() Method

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Address: TwinStar, South Block – 1202, 150 Ft Ring Road, Nr. Nana Mauva Circle, Rajkot(360005), Gujarat, India

Call: (+91) 9409548155

Email: support@appdividend.com

Online Platform

  • Pricing
  • Instructors
  • FAQ
  • Refund Policy
  • Support

Links

  • About Us
  • Contact Us
  • Privacy Policy
  • Terms of services

Tutorials

  • Angular
  • React
  • Python
  • Laravel
  • Javascript
Copyright @2024 AppDividend. All Rights Reserved
Appdividend