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 Tutorial
From the course: Python Functions for Data Science
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
Python print() function2m 30s
-
(Locked)
Python input() function2m 1s
-
(Locked)
Python abs() function1m 57s
-
(Locked)
Python round() function2m 10s
-
(Locked)
Python min() function1m 42s
-
(Locked)
Python max() function1m 41s
-
(Locked)
Python sorted() function3m 39s
-
(Locked)
Python sum() function1m 1s
-
(Locked)
Python len() function2m 28s
-
(Locked)
Python type() function2m 22s
-
-
-
-
-
-
-
-