Sum of Integers – ‘int’ object is not iterable

Look at the documentation:

sum(iterable[, start])

Sums start and the items of an iterable from left to right and returns the total. start defaults to 0. The iterable‘s items are
normally numbers, and the start value is not allowed to be a string.

So you have to pass an iterable as argument, not an int!

sum((a, b)) should work correctly.

This is a function which is intended to be used when you have many values stored in a list (for example), if you want to sum two values, you should simply use a + b.

Leave a Comment