Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialLuke Tate
Courses Plus Student 2,256 PointsWhy does the "sum" have no definition? Is it built in code?
Is "sum" only used for format statements or can they be used in other statements as well?
2 Answers
Ave Nurme
20,907 PointsHi Luke
You are correct - sum() is indeed a built-in function. Here's a list of Python's built-in functions: https://docs.python.org/3/library/functions.html
You can use sum() however you need. Here's a few examples for you:
# Example 1
lst = [2, 4, 5, 7, 9]
print(sum(lst)) # 27 (2+4+5+7+9)
# Example 2
lst = [1, 3, 2]
print(sum(lst, 10)) # 16 (1+3+2+10)
Hope this helps!
Luke Tate
Courses Plus Student 2,256 PointsThanks! Ave!