python
One line code to get the sum of a list in python
You can get the sum of items values that exist in a list using the sum() function of python. You can pass the list to the sum() method and it will return the sum of the all list items.
values = [1,2,3,4,5]
sum_of_values = sum(values)
print(sum_of_values)
# -> 15
Was this helpful?
Similar Posts
- Create a List from sum of two Lists in Python
- Python - regex , replace multiple spaces with one space
- Single line if else condition python
- Assign multi-line string to a variable in python
- Python Strings: Learn How to Add Line Breaks
- Python code to check if a given number exists in a list
- Python code to get the first character from a string