# Hi, In Interview I can up with question, How to sum the list by using robot framework keyword

**URL:** <https://forum.robotframework.org/t/hi-in-interview-i-can-up-with-question-how-to-sum-the-list-by-using-robot-framework-keyword/4764>\
**Category:** Robot Framework\
**Created:** [30 September 2022 07:18 UTC](https://forum.robotframework.org/t/hi-in-interview-i-can-up-with-question-how-to-sum-the-list-by-using-robot-framework-keyword/4764 "2022-09-30T07:18:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dineshsampath05](https://avatars.discourse-cdn.com/v4/letter/d/85f322/32.png) [@Dineshsampath05](https://forum.robotframework.org/u/Dineshsampath05)\
**Post date:** [30 September 2022 07:18 UTC](https://forum.robotframework.org/t/hi-in-interview-i-can-up-with-question-how-to-sum-the-list-by-using-robot-framework-keyword/4764/1 "2022-09-30T07:18:28Z")

</div>

Basic sum of the list program,  
sum=0

for i in [1, 2, 3, 4]:

```
sum=sum+i

```

print(sum)

Robot framework sum of the list, I’m trying:  
\*\*\* Settings \*\*\*  
Library SeleniumLibrary  
Library DatabaseLibrary  
Library Collections

\*\*\* Test Cases \*\*\*  
Additon of lists  
@{list}= Create List 1 2 3 4  
${index}= Set Variable 0  
FOR ${i} IN ${list}  
${index}= Evaluate ${index}+${i}  
Log ${index}  
END

## Error: Additon of lists | FAIL | Evaluating expression ‘0+[‘1’, ‘2’, ‘3’, ‘4’]’ failed: TypeError: unsupported operand type(s) for +: ‘int’ and ‘list’

List | FAIL |  
1 test, 0 passed, 1 failed

---

<div class="post-metadata">

**Author:** ![HelioGuilherme66](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/helioguilherme66/32/34_2.png) [@HelioGuilherme66](https://forum.robotframework.org/u/HelioGuilherme66)\
**Post date:** [30 September 2022 22:24 UTC](https://forum.robotframework.org/t/hi-in-interview-i-can-up-with-question-how-to-sum-the-list-by-using-robot-framework-keyword/4764/2 "2022-09-30T22:24:42Z")

</div>

Here is your corrected example (note the expanding symbol @ for the list):

```nohighlight
***Settings***
Library SeleniumLibrary
Library DatabaseLibrary
Library Collections

***Test Cases***
Addition of lists
    @{list}= Create List 1 2 3 4
    ${index}= Set Variable 0
    FOR ${i} IN @{list}
        ${index}= Evaluate ${index}+${i}
        Log ${index}
    END

```

Another (just to show enumeration 😉 ):

```nohighlight
***Test Cases***
Addition of lists other
    @{list}= Create List 1 2 3 4
    ${sum}= Set Variable 0
    FOR ${index} ${i} IN ENUMERATE @{list}
        ${sum}= Evaluate ${sum} + int(${list[${index}]})
        Log ${sum}
    END

```

---

<div class="post-metadata">

**Author:** ![Dineshsampath05](https://avatars.discourse-cdn.com/v4/letter/d/85f322/32.png) [@Dineshsampath05](https://forum.robotframework.org/u/Dineshsampath05)\
**Post date:** [1 October 2022 13:43 UTC](https://forum.robotframework.org/t/hi-in-interview-i-can-up-with-question-how-to-sum-the-list-by-using-robot-framework-keyword/4764/3 "2022-10-01T13:43:32Z")

</div>

Thanks a lot 🙂
