close

[Solved] Type: unsupported operand type(s) for +=: ‘int’ and ‘list’

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Type: unsupported operand type(s) for +=: ‘int’ and ‘list’ in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Type: unsupported operand type(s) for +=: ‘int’ and ‘list’ Error Occurs?

Today I get the following error Type: unsupported operand type(s) for +=: ‘int’ and ‘list’ in python.

How To Solve Type: unsupported operand type(s) for +=: ‘int’ and ‘list’ Error ?

  1. How To Solve Type: unsupported operand type(s) for +=: 'int' and 'list' Error ?

    To Solve Type: unsupported operand type(s) for +=: 'int' and 'list' Error Here s is an int and wordis 2D List. So, In for line in worldline is a 1D List. It is impossible to add a List into a int type. Here, s+=line in incorrect

  2. Type: unsupported operand type(s) for +=: 'int' and 'list'

    To Solve Type: unsupported operand type(s) for +=: 'int' and 'list' Error Here s is an int and wordis 2D List. So, In for line in worldline is a 1D List. It is impossible to add a List into a int type. Here, s+=line in incorrect

Solution 1

In

s=0
for line in world:
    s+=line

Here s is an int and wordis 2D List. So, In for line in worldline is a 1D List. It is impossible to add a List into a int type. Here, s+=line in incorrect

So, In s+=line, you can replace s+=sum(line). I think you have found your answer.

Try this:

s=0
for line in world:
    s+=sum(line)

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read