Question 1:

To sum a list of numbers, use sum:

xs = [1, 2, 3, 4, 5]
print(sum(xs))

This outputs:

15

Question 2:

So you want (element 0 + element 1) / 2, (element 1 + element 2) / 2, ... etc.

We make two lists: one of every element except the first, and one of every element except the last. Then the averages we want are the averages of each pair taken from the two lists. We use zip to take pairs from two lists.

I assume you want to see decimals in the result, even though your input values are integers. By default, Python does integer division: it discards the remainder. To divide things through all the way, we need to use floating-point numbers. Fortunately, dividing an int by a float will produce a float, so we just use 2.0 for our divisor instead of 2.

Thus:

averages = [(x + y) / 2.0 for (x, y) in zip(my_list[:-1], my_list[1:])]
Answer from Karl Knechtel on Stack Overflow
🌐
W3Schools
w3schools.com › python › ref_func_sum.asp
Python sum() Function
Python Examples Python Compiler ... Python Interview Q&A Python Bootcamp Python Training ... The sum() function returns a number, the sum of all items in an iterable....
🌐
GeeksforGeeks
geeksforgeeks.org › python › sum-function-python
sum() function in Python - GeeksforGeeks
November 27, 2025 - The sum() function in Python is used to add up numbers from any iterable such as a list, tuple, set, or dictionary values.
🌐
AskPython
askpython.com › home › how to use the python sum() function
How to Use The Python sum() Function - AskPython
May 12, 2026 - I keep coming back to the Python sum() function whenever I need a quick way to add up numbers. It is one of those built-in tools that seems simple on the
🌐
Real Python
realpython.com › python-sum-function
Python's sum(): The Pythonic Way to Sum Values – Real Python
July 21, 2023 - In this step-by-step tutorial, you'll learn how to use Python's sum() function to add numeric values together. You also learn how to concatenate sequences, such as lists and tuples, using sum().
🌐
Programiz
programiz.com › python-programming › methods › built-in › sum
Python sum()
Python list() The sum() function ... 339 · The syntax of the sum() function is: sum(iterable, start) The sum() function adds start and items of the given iterable from left to right....
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-sum
Python sum() | DigitalOcean
August 4, 2022 - Python sum() function is used to get the sum of numbers of an iterable.
Find elsewhere
🌐
The New Stack
thenewstack.io › home › what is python’s sum() function and how do you use it?
What Is Python's sum() Function and How Do You Use It? - The New Stack
September 5, 2024 - What the above does is devise the sum of the numbers from num = sum(numbers) by the length of the list (which is 4). So 25 divided by 4 equals 6.25. The Python sum() function will come in very handy as you continue your journey with this widely used language.
🌐
Flexiple
flexiple.com › python › python-sum
Various ways to sum numbers in Python | Flexiple Tutorials | Python - Flexiple
March 14, 2022 - We can use Python libraries or can use other methods for the same. Let us look at them one by one. ... Iterable - the values to be added. It is a compulsory field. Iterators can be lists, tuples, strings or dictionaries - basically, a group of numbers. Start - the value to which the iterable is to be added. It is an optional field and takes the value “0” if we don’t enter any. # using syntax sum(iterable) a = (1, 3, 5, 7, 9) b = sum(a) print(b)
🌐
Codecademy
codecademy.com › docs › python › built-in functions › sum()
Python | Built-in Functions | sum() | Codecademy
June 20, 2023 - The sum() function takes in an iterable object, such as a list or tuple, and returns the sum of all elements. ... Learn to analyze and visualize data using Python and statistics.
🌐
Career Karma
careerkarma.com › blog › python › python sum: a step-by-step guide
Python Sum: A Step-By-Step Guide | Career Karma
December 1, 2023 - The Python sum() function calculates the total of all numerical values in an iterable. sum() works with both integers and floating-point numbers.
🌐
Real Python
realpython.com › ref › builtin-functions › sum
sum() | Python’s Built-in Functions – Real Python
The built-in sum() function provides a Pythonic way to add together the items of an iterable.
🌐
University of Vermont
uvm.edu › ~cbcafier › cs1210 › book › 11_loops › loops_and_summation.html
Math and Python: loops and summation – Clayton Cafiero
While we have the Python built-in function sum() which sums the elements of a sequence (provided the elements of the sequence are all of numeric type), it’s instructive to see how we can do this in a loop (in fact, summing in a loop is exactly what the sum() function does).
🌐
Medium
medium.com › @johnusa4567 › python-sum-function-explained-with-examples-a51c67098bfb
python sum Function Explained with Examples | by John Usa | Medium
September 15, 2025 - The python sum function is a built-in feature that makes it simple to add numbers from an iterable such as a list, tuple, or set. It is often used when working with collections of numerical data where a total is needed quickly without writing loops.
🌐
iO Flood
ioflood.com › blog › python-sum
Python Sum() Function: Ultimate Usage Guide
February 6, 2024 - It’s a straightforward and efficient way to perform addition operations in Python. ... # Here is a list of numbers digits = [4, 2, 9, 3, 5] # Using the sum function to add all numbers in the list total = sum(digits) print(total) # Output: # 23
🌐
Tutorialspoint
tutorialspoint.com › python › sum_function.htm
Python sum() Function
The Python sum() function returns the sum of all numeric items in any iterable, such as a list or tuple. It also accepts an optional "start" argument which is 0 by default. If given, the numbers in the list are added to the start value.
🌐
Vultr Docs
docs.vultr.com › python › built-in › sum
Python sum() - Sum Iterable Values | Vultr Docs
November 25, 2024 - The sum() function in Python provides a straightforward way to calculate the total of the numbers in an iterable, such as a list or tuple.
🌐
Kodeclik
kodeclik.com › python-sum-function
Python's sum() function
October 27, 2025 - Given an iterable, Python’s sum() function adds up the elements in the iterable and returns the sum. It takes an optional parameter which is the start value of the sum.
🌐
FavTutor
favtutor.com › blogs › sum-python
Sum in Python: How to use sum() function? with Examples
November 25, 2022 - A sum function is a powerful tool in python that can be used to find the total of all the items in a given iterable. There is only one error that can occur when using the sum function and that is the iterable should not contain anything else ...