how does python know it should not add the values of the first list and the second. for example if the first list consists of only one number [2] and y is [3] then:
list1 + list 2 should return 5.
Python will not arithmetically add the values concatenated to the list. It will extend the list to include those values.
[1, 2, 3] + [9, 8, 7] => [1, 2, 3, 9, 8, 7]
The process of adding an array sequence is one of reduction, which means acting upon the list to reduce it to a single element with a sum. We can then set it as the value, and drop the list.
>>> a = [1, 2, 3, 9, 8, 7]
>>> while len(a) > 1:
a[0] += a.pop(1)
>>> a[0]
30
>>> a = a.pop()
>>> a
30
>>>