Sum Function in Python

Level 121 keystrokes

This calculates the sum of a list. The sum() function adds all elements in an iterable.

Python code

# sum() adds up all the elements of an iterable such as a list
# 1 + 2 + 3 is 6, so 6 is printed
1print(sum([1, 2, 3]))

Output

6
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Python code and how often they appear.

  • ,× 2
  • (× 2
  • )× 2
  • [× 1
  • ]× 1

More Python examples at level 1

← Python typing practice