Program to Calculate Percentage in Python

Overview
A percentage is the proportion of the totality. In other words, a percentage is a figure or ratio that is written as a fraction of 100. In this article, we calculate the percentage using the Python programming language in three ways.
- Calculating Percentage in Python using List Comprehension and len()
- Calculating Percentage in Python using filter(), lambda, and len()
- Calculating Percentage in Python using list(), map() and find()
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
Calculating Percentage in Python
We are going to use the input_list and calculate the percentage of the number of even elements in the list.
- input_list = [2, 7, 6, 3, 19, 8, 14, 26]
- Number of even elements: 5
- Percentage of number of even elements in the list: 62.5
- Explanation:
Method 1: Using List Comprehension and len()
Output:
Here, we create a list of even elements using list comprehension and calculate the length of the list using len(). Then divide by the length of the original list and multiply the result by 100 to obtain the percentage count.
Method 2: Calculating Percentage in Python Using filter(), lambda and len()
Output
Using filter() and lambda, we carry out tasks to obtain even elements in the list and then calculate the length of the list using len(). Then divide by the length of the original list and multiply the result by 100 to obtain the percentage count.
Method 3: Calculating Percentage in Python with the use of list(), map(), and find()
Output
Convert all the list elements to string and then check if the numbers in the list start with the digit 6 and add them to the output list. Then divide the lengths of both lists to find the percentage of the count of even values in the input list.
Scaler Placement Report and Statistics
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
Similar Python Programs
Conclusion
We used three methods to calculate percentages in the Python programming language.
- Using List Comprehension and len()
- Using filter(), lambda and len()
- Using list(), map() and find()