Python error: unsupported operand type(s) for -: 'str' and 'str'

0 votes

Hi. I am new to Python and I am practising to code. But I am facing some issues.

>>> a=input('>')


>>> b=input('>')


>>> print(b-a)

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

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


Please help me solve this error

May 12 in Python by Tina

1 answer to this question.

0 votes

Hi. This error is caused because you are trying to do a subtraction between two strings. When you take the input, the input data is stored as a string by default. To apply subtraction, you can change the type into int(or float)

answered May 12 by Anjali

Related Questions In Python

0 votes
0 answers

TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

Hi guys i have below code . ...READ MORE

Oct 30 in Python by sumanth
• 190 points
0 votes
1 answer

Python error "TypeError: Cannot compare types 'ndarray(dtype=int64)' and 'str'"

Hey @Ashish, change the emotion_map to the ...READ MORE

answered May 30 in Python by Mir
0 votes
1 answer

What's the canonical way to check for type in Python?

To check if o is an instance ...READ MORE

answered Aug 24, 2018 in Python by Priyaj
• 56,920 points
0 votes
1 answer

When I create and remove files rapidly on windows using python I get WindowsError (Error 5)

Here's the short answer: disable any antivirus or ...READ MORE

answered Aug 31, 2018 in Python by charlie_brown
• 7,720 points
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 345 views
+4 votes
6 answers
0 votes
1 answer
0 votes
1 answer

How to write data to a file in Python?

Refer to the below code. data=’whatever your data ...READ MORE

answered May 12 in Python by Shaam