Summing Values the Pythonic Way With sum() (Overview)
Python’s built-in function sum()
is an efficient and Pythonic way to sum a list of numeric values. Adding several numbers together is a common intermediate step in many computations, so sum()
is a pretty handy tool for a Python programmer.
As an additional and interesting use case, you can concatenate lists and tuples using sum()
, which can be convenient when you need to flatten a list of lists.
In this video course, you’ll learn how to:
- Sum numeric values by hand using general techniques and tools
- Use Python’s
sum()
to add several numeric values efficiently - Concatenate lists and tuples with
sum()
- Use
sum()
to approach common summation problems - Use appropriate values for the arguments in
sum()
- Decide between
sum()
and alternative tools to sum and concatenate objects
This knowledge will help you efficiently approach and solve summation problems in your code using either sum()
or other alternative and specialized tools.
If you’d like to learn more about the REPL used in this course, check out Discover bpython: A Python REPL With IDE-Like Features. Note that all the code in this course will also run in the Python standard REPL.
00:00
Summing Values the Pythonic Way With sum()
.
00:05
Python’s built-in sum()
is an efficient and Pythonic way to sum a list of numeric values. Adding several numbers together is a common intermediate step in many computations, so sum()
is a handy tool for a Python programmer.
00:18
You can also concatenate lists and tuples using sum()
, which can be useful when you need to flatten a list of lists.
00:27
In this course, you’ll learn how to sum numeric values by hand using general techniques and tools, use Python’s sum()
to add several numeric values efficiently, concatenate lists and tuples with sum()
, use sum()
to approach common summation problems, use appropriate values for the arguments in sum()
, and decide between sum()
and alternative tools to sum and concatenate objects.
00:52
This knowledge will help you efficiently approach and solve summation problems in your code, either using sum()
or alternative and specialized tools.
01:02 Any code that you see running in the REPL in this course will be using the bpython interpreter. This is a replacement Python interpreter that offers a number of enhancements, including code highlighting and suggestions.
01:13
But any code you see running on-screen will work in the Python REPL, which is typically accessed by typing python
or python3
at your terminal or command-line prompt. So now you know what’s going to be covered, let’s get started.
Become a Member to join the conversation.