What does "unsupported operand type(s) for -: 'int' and 'tuple'" means?
Asked Answered
M

3

7

I got a error saying:

unsupported operand type(s) for -: 'int' and 'tuple'

How do I correct it?

from scipy import integrate
cpbar = lambda T: (3.826 - (3.979e-3)*T + 24.558e-6*T**2 - 22.733e-9*T**3 + 6.963e-12*T**4)*8.314
deltahbarCH4 = integrate.quad(cpbar,298,1000)
var = deltahbarCH4

hRPbar = hRPbar + (deltahbarCO2 + 2*deltahbarH2O - var -2*deltahbarO2)
Mantle answered 8/4, 2014 at 18:54 Comment(1)
It means that you are trying to use the subtraction operator - between a number and a tuple. It will be easier to debug if you tell us which line it is on.Disjoint
T
4

integrate.quad() returns a tuple; deltahbarCO2 + 2*deltahbarH2O is an integer, you are trying to subtract the var tuple.

If you wanted just the integral y of the integrate.quad() result, use the first element of that tuple:

var = deltahbarCH4[0]

or use tuple assignment:

var, err = deltabarCH4
Tullis answered 8/4, 2014 at 19:0 Comment(0)
D
2

That error means that you are trying to use the subtraction operator - between a number and a tuple.

Based on the documentation, you probably want: var = deltahbarCH4[0], since that will give you the actual value of the integral, which you are computing with on a later line.

Disjoint answered 8/4, 2014 at 19:0 Comment(0)
H
0

I got the same error below:

TypeError: unsupported operand type(s) for -: 'int' and 'tuple'

When trying to subtract tuple type from int type as shown below:

    # int 
print(10 - (3,))
          # tuple

So, I changed tuple type to int type as shown below:

print(10 - 3)

Then, the error above was solved:

7
Hercule answered 23/12, 2022 at 14:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.