In this article, we will explore different ways to calculate the Area and Perimeter of a Circle using Python, with detailed explanations and examples.
Table of contents
What is a Circle?
A circle is a two-dimensional (2D) shape where all points on the boundary are equidistant from a fixed central point. This fixed point is called the center, and the constant distance from the center to any point on the circle is called the radius (r).
Examples of Circles in Real Life are the wheels of a car, clocks, coins, rings, etc.

Understand the Area of a Circle
The area of a circle is the total space enclosed within its boundary. It is measured in square units such as square centimeters (cm²), square meters (m²), or square inches (in²).
Formula to Calculate the Area of a Circle:
Area = πr2
- A (Area) = Total space inside the circle
- r (Radius) = Distance from the center to the edge of the circle
- π(Pi) ≈ 3.14159
For Example, If a circle has a radius of 5 meters:
then Area = π × (52) = 3.14159 × 25 = 78.54 m²
Understand the Perimeter(Circumference) of a Circle
The perimeter of a circle is the total distance around its edge — essentially, it is the circumference of the circle.
There are two formulas you can use, depending on what’s given:
1. Using Radius (r): Perimeter = Circumference = 2πr
2. Using Diameter (d): Perimeter = Circumference = πd
Where:
- r = Radius (distance from center to edge)
- d = Diameter (distance across the circle through the center), and
d = 2r - π (pi) ≈ 3.14159
For Example, If the radius = 7 cm:
Then, the Circumference= 2 × π × 7 ≈ 2 × 3.1416 × 7 = 43.98 cm
If the diameter = 10 m:
Then, the Circumference = π × 10 = 31.42 m
1. How to Calculate Area and Circumference of a Circle
Below are the steps to calculate the Area and Perimeter of Circle in Python:
- Import the
mathModulePython has a built-in
mathmodule that provides the constant π (pi).
To use π, import the module:import math - Define the Radius
Assign a value to the radius of the circle.
- Apply the Formula to calculate the Area
Use the formula
A = πr².
In Python:area = math.pi * radius ** 2
Here,math.piprovides the value of π andradius ** 2calculates r².
The Exponentiation operator (**) in Python raises a number to the power of another number. For Example,print(3 ** 2)# Output: 9 (3²) - Apply the Formula to calculate the Perimeter
The formula to calculate the Perimeter of a circle is:
perimeter = 2 * math.pi * radius - Mention the Correct Unit
If the measurements are in meters, the area will be in square meters (m²), and the Perimeter will be in meters (m).
- Display the result
Display Area and Perimeter using the
print()function
Code Example
Output:
Area is 78.53981633974483 square units
Perimeter is 31.41592653589793 units
2. Calculate Using User Inputs
If you want to calculate area using the radius of the circle specified by user then use the input() function.
The input() function allow us to get input from the user while a Python script is running. It pauses the execution of your program and waits for the user to type something into the console (or terminal) and press the Enter key.
The input() always returns the user’s input as a string, regardless of whether the user typed numbers, letters, or symbols. So you must convert it to numbers using the float() function.
Code Example
Output:
Enter the radius of the circle: 5
Area is 78.53981633974483 square units and Perimeter is 31.41592653589793 units
3. Calculate Using a Function
A function allows us to write the calculation once and use it multiple times without repeating code.There are multiple advantages of using a function to calculate the area of a circle.
- If a program requires multiple area calculations, a function makes it scalable.
- Avoid errors: A function helps prevent mistakes by keeping the formula in one place.
- Easier Debugging & Updating: If the formula needs to be updated or changed, a function makes it easy to modify in one place.
In the example below, we have different functions to calculate area and perimeter, which can be reused for multiple circles without repeating the code.
Code Example
4. Calculate Area of Circle Using Class (OOP)
Object-Oriented Programming (OOP) is a structured way to write code by creating classes and objects. A class is a blueprint for creating objects, while an object is an instance of a class.
This approach provides better structure, reusability, and maintainability in your code. This approach is highly useful, especially for larger applications where multiple circles need to be handled efficiently.
The following are the advantages of using OOP to calculate the area and perimeter of a circle:
- Reusability: If you need to calculate the area of multiple circles, you can create multiple objects.
- Extensibility: With OOP, we can easily extend the class to calculate the circumference without affecting the existing structure.
Code Example:
Explanation:
- Define a Class
- Define a class named
Circle. - The class will store the radius of the circle.
- Define a class named
- Create a Constructor (
__init__method)- The constructor (
__init__) initializes the side when an object is created. - The
selfkeyword refers to the current instance of the class.
- The constructor (
- Create a Method to Calculate Area
- Define a method
calculate_area()inside the class. - This method returns the area using the formula:
Area = πr²
- Define a method
- Create a Method to Calculate Perimeter
- Define a method
calculate_perimeter()inside the class. - This method returns the perimeter using the formula:
2 * math.pi * radius
- Define a method
- Create an Object of the Class
- Use
circle= Circle(5)to create a circle with:radius = 5
- Use
- Call the Method to get the Area
- Use
circle.calculate_area()to get the area of the object. - Use
circle.calculate_perimeter()to get the perimeter of the object.
- Use
- Store the result in a variable and display it using
print().
5. Calculate Area of Circle Using Lambda
A lambda function in Python is a small, anonymous function that can have multiple arguments but only one expression, which is evaluated and returned. For a more compact implementation, you can use a lambda function.
A lambda function syntax: lambda arguments: expression
lambda→ Keyword to define the function.arguments→ Input parameters (like a normal function).expression→ A single operation that returns a result.
Code Example
Explanation
radiusis the input parameter.- To calculate the Area:
math.pi * radius ** 2is the calculation expression.circle_areais the name to call the anonymous lambda function.
- To calculate the Perimeter:
2 * math.pi * radiusis the calculation expression.circle_perimeteris the name to call the anonymous lambda function.
Summary
Calculating the area and circumference of a circle in Python is both simple and versatile. Whether you’re using basic arithmetic, taking user input, defining functions, applying object-oriented programming, or using lambda expressions, each method provides a clear way to implement the logic efficiently.
These approaches not only reinforce your understanding of Python fundamentals but also build a strong foundation for solving real-world mathematical problems. Depending on your use case—quick calculations, reusable code, or scalable design—you can choose the method that fits best.

Leave a Reply