how to add integers in a list python code example
Example 1: how to add list numbers in python
lst = []
num = int(input('How many numbers: '))
for n in range(num):
numbers = int(input('Enter number '))
lst.append(numbers)
print("Sum of elements in given list is :", sum(lst))
Example 2: how do i add the integers in a list with itsself in python
x = [2, 4, 7, 12, 3]
sum_of_all_numbers= sum(x)
or
x = [2, 4, 7, 12, 3]
sum_of_all_numbers= reduce(lambda q,p: p+q, x)
Example 3: how to add numbers into a list python
a_list = [1, 2, 3]
integers_to_append = 4.
a_list. append(integers_to_append)
print(a_list)