Why is there difference between cmd line and .py file?
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Wed Jan 6 00:25:30 EST 2016
On Wednesday 06 January 2016 07:37, John Gordon wrote:
> The built-in function sum() returns a single value, not a list, so this
> is a reasonable error.
Not quite. It depends on what arguments you give it.
py> a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
py> sum(a, [])
[1, 2, 3, 4, 5, 6, 7, 8, 9]
But your point is well taken. In this case, the call:
sum(expectation_A)
defaults to an initial value of 0, so expectation_A almost certainly is a
list of numbers, in which case sum will return a single number, not a list
or array.
--
Steve
More information about the Python-list
mailing list