Fix Python TypeError: unsupported operand type(s) for +: ‘range’ and ‘float’ – Python Tutorial

By | November 12, 2020

When you are using python range() function, you may get this type error: TypeError: unsupported operand type(s) for +: ‘range’ and ‘float’. In this tutorial, we will introduce you how to fix it.

Look at example code below:

i = range(8)+0.2

Run this code, you will get this type error.

Fix TypeError - unsupported operand type(s) for - 'range' and 'float'

How to fix this type error?

It is very easy to fix this error. You can do it as follows:

i = [j+0.2 for j in range(8)]

Run this code, you will find this type error is fixed.

Leave a Reply