TypeError: unsupported operand type(s) (tested fix)

TypeError: unsupported operand type(s) for /: 'str' and 'int' (or +, -, *) means the operator doesn't work between those two types. We reproduced eight common combinations in Python 3.13 and tested the fix for each.

1. Reading the message

The message names the operator and the two types, left then right. That tells you which value has the wrong type. We tried eight common combinations:

from decimal import Decimal
cases = ['"10" / 2', '"a" - "b"', 'None + 1', '2 * None', '[1, 2] / 2', '(1, 2) / 2', 'Decimal("1.5") * 1.5', '{1} + {2}']
for expr in cases:
    try:
        eval(expr); print(f"{expr:22} OK")
    except TypeError as e:
        print(f"{expr:22} TypeError: {e}")

Output:

"10" / 2               TypeError: unsupported operand type(s) for /: 'str' and 'int'
"a" - "b"              TypeError: unsupported operand type(s) for -: 'str' and 'str'
None + 1               TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
2 * None               TypeError: unsupported operand type(s) for *: 'int' and 'NoneType'
[1, 2] / 2             TypeError: unsupported operand type(s) for /: 'list' and 'int'
(1, 2) / 2             TypeError: unsupported operand type(s) for /: 'tuple' and 'int'
Decimal("1.5") * 1.5   TypeError: unsupported operand type(s) for *: 'decimal.Decimal' and 'float'
{1} + {2}              TypeError: unsupported operand type(s) for +: 'set' and 'set'

The usual culprits are a str that should be a number (from input(), CSV or JSON), None (a function with no return), a list or tuple where you meant each item, and Decimal mixed with float. Sets support |, & and -, but not +.

2. The fix for each

from decimal import Decimal
print(int("10") / 2, float("2.5") * 2)
print(Decimal("1.5") * Decimal("1.5"), float(Decimal("1.5")) * 1.5)
print([x / 2 for x in [1, 2]], {1} | {2})

Output:

5.0 5.0
2.25 2.25
[0.5, 1.0] {1, 2}

Convert strings with int() or float() when you read them. Keep Decimal math all-Decimal, building them from strings, or convert to float on purpose. Use a comprehension to apply an operator to each item of a list. Use | for set union.

3. NoneType: the missing return

'NoneType' and 'int' nearly always means a function fell off the end without return. The traceback points at the arithmetic, not at the function:

def total(items):
    s = 0
    for i in items:
        s += i
    # forgot: return s

count = total([1, 2])
print(count * 2)

Output:

Traceback (most recent call last):
  File "/tmp/uo/b3.py", line 8, in <module>
    print(count * 2)
          ~~~~~~^~~
TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'

Add the return, or check for None before doing math. For + with a string on the left, Python gives a different message. See can only concatenate str (not "int") to str.

Frequently asked questions

How do I fix unsupported operand type(s) for /: 'str' and 'int'?

The left value is a string. Convert it first: int(x) / 2 or float(x) / 2.

What does unsupported operand type(s) for +: 'NoneType' and 'int' mean?

One value is None, usually because a function has no return statement. Add the return or check for None first.

Why can't I multiply a Decimal by a float?

Decimal and float can't be mixed in arithmetic. Use Decimal('1.5') for both, or convert the Decimal with float().

Written with AI assistance. Measured on 2026-10-22 on Debian with Python 3.13.5: /, -, + and * across str, int, None, list, tuple, Decimal/float and set, the conversion fixes, and a function missing its return. Every block was run verbatim and its output pasted unedited. PlainHeaders is our extension; Python is free.