From the course: Python Functions for Data Science

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Python sum() function

Python sum() function - Python Tutorial

From the course: Python Functions for Data Science

Start my 1-month free trial

Python sum() function

- The built-in function sum is a powerful computational tool, when working with numerical data in Python. The function sum is best suited to take in a sequence of integers as input. And it returns the sum of the items in the given sequence. To illustrate how this function can be used, I'll be walking through a couple of examples. First, let's say that I have a variable named nums, that contains a tuple of integers. To compute the sum of the items in nums, I can call the function sum and pass in nums. It will look like this. Now, go ahead and run this cell. There. I got 18 as a sum. Next, say that I have a variable named listN that contains a list of integers. To compute the sum of the items in listN, I can call the function sum and pass in listN. It would look like this. I'll go ahead and run this cell. There it is. I got negative 21 as the sum. Now that you've seen how to use the function sum, this tool is at…

Contents