Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Summarizing Data with Built-in Functions | Organizing and Summarizing Data
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Python for Daily Tasks

bookSummarizing Data with Built-in Functions

When you work with collections of data in Python, such as lists of numbers, you often need to quickly summarize or analyze the information. Python provides several built-in functions that make these tasks simple and fast. The most commonly used functions for summarizing data in lists are sum(), len(), min(), and max().

  • The sum() function adds up all the numbers in a list;
  • The len() function returns the number of items in a list;
  • The min() function finds the smallest value in a list;
  • The max() function finds the largest value in a list.

These functions are easy to use and can help you make sense of your data without writing complex code.

1234567
# Calculate the total and average of weekly expenses expenses = [45, 30, 60, 25, 50, 40, 35] total = sum(expenses) average = total / len(expenses) print("Total expenses for the week:", total) print("Average daily expense:", average)
copy

Using these built-in functions, you can quickly get useful insights from everyday data. For example, by calculating the total and average of your weekly expenses, you can see how much you are spending and adjust your budget if needed. Similarly, you can use min() and max() to find the lowest and highest values in a list, such as daily temperatures or scores, which helps you spot trends or outliers in your data.

1234567
# Find the highest and lowest daily temperatures temperatures = [68, 71, 65, 70, 74, 69, 72] highest = max(temperatures) lowest = min(temperatures) print("Highest temperature of the week:", highest) print("Lowest temperature of the week:", lowest)
copy

1. Which function returns the number of items in a list?

2. How do you calculate the average of a list of numbers in Python?

3. Fill in the blanks to find the maximum value in a list.

question mark

Which function returns the number of items in a list?

Select the correct answer

question mark

How do you calculate the average of a list of numbers in Python?

Select the correct answer

question-icon

Fill in the blanks to find the maximum value in a list.

numbers = [3, 7, 2, 9, 4] result = (numbers) print(result)
9

Click or drag`n`drop items and fill in the blanks

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 2. Kapittel 4

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

Suggested prompts:

Can you explain how to use these functions with other types of data?

What happens if the list is empty when using these functions?

Can you show more examples of summarizing data with built-in functions?

bookSummarizing Data with Built-in Functions

Sveip for å vise menyen

When you work with collections of data in Python, such as lists of numbers, you often need to quickly summarize or analyze the information. Python provides several built-in functions that make these tasks simple and fast. The most commonly used functions for summarizing data in lists are sum(), len(), min(), and max().

  • The sum() function adds up all the numbers in a list;
  • The len() function returns the number of items in a list;
  • The min() function finds the smallest value in a list;
  • The max() function finds the largest value in a list.

These functions are easy to use and can help you make sense of your data without writing complex code.

1234567
# Calculate the total and average of weekly expenses expenses = [45, 30, 60, 25, 50, 40, 35] total = sum(expenses) average = total / len(expenses) print("Total expenses for the week:", total) print("Average daily expense:", average)
copy

Using these built-in functions, you can quickly get useful insights from everyday data. For example, by calculating the total and average of your weekly expenses, you can see how much you are spending and adjust your budget if needed. Similarly, you can use min() and max() to find the lowest and highest values in a list, such as daily temperatures or scores, which helps you spot trends or outliers in your data.

1234567
# Find the highest and lowest daily temperatures temperatures = [68, 71, 65, 70, 74, 69, 72] highest = max(temperatures) lowest = min(temperatures) print("Highest temperature of the week:", highest) print("Lowest temperature of the week:", lowest)
copy

1. Which function returns the number of items in a list?

2. How do you calculate the average of a list of numbers in Python?

3. Fill in the blanks to find the maximum value in a list.

question mark

Which function returns the number of items in a list?

Select the correct answer

question mark

How do you calculate the average of a list of numbers in Python?

Select the correct answer

question-icon

Fill in the blanks to find the maximum value in a list.

numbers = [3, 7, 2, 9, 4] result = (numbers) print(result)
9

Click or drag`n`drop items and fill in the blanks

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 2. Kapittel 4
some-alt