Unsupported operand type s for int and str

0 votes

I am currently learning Python and am not very good at it and am confused as to what is going on. Have shared my code below:- 

num1 = int(input("What is your first number? ")) 
num2 = int(input("What is your second number? ")) 
num3 = int(input("What is your third number? ")) 
numlist = [num1, num2, num3] 

print(numlist) 
print("Now I will remove the 3rd number") 
print(numlist.pop(2) + " has been removed") 
print("The list now looks like " + str(numlist))
When I run the program, entering in numbers for num1, num2 and num3, it returns this:

Traceback (most recent call last):
TypeError: unsupported operand type(s) for +: 'int' and 'str'

Feb 23 in Python by Rahul
• 9,680 points
1,475 views

1 answer to this question.

0 votes

You seem to be trying to train a string and an integer, which is incorrect.

Alter the print(numlist.pop(2)+" has been removed") to any of these:

Explicit int to str conversion:
print(str(numlist.pop(2)) + " has been removed")

Use , instead of +:
 

print(numlist.pop(2), "has been removed")

String formatting:
 

print("{} has been removed".format(numlist.pop(2)))

answered Feb 23 by Aditya
• 7,660 points

Related Questions In Python

0 votes
3 answers

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

& is "bitwise and" operand in Python, you ...READ MORE

answered Dec 11, 2020 in Python by Rajiv
• 8,910 points
73,094 views
0 votes
0 answers

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

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

Oct 30, 2019 in Python by sumanth
• 190 points
10,563 views
0 votes
1 answer

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

Hey, @William For me the code is working ...READ MORE

answered Mar 11, 2020 in Python by Roshni
• 10,520 points
2,489 views
+1 vote
0 answers

TypeError: unsupported operand type(s) for /: 'list' and 'list'

This is my part of code, why ...READ MORE

May 17, 2020 in Python by anonymous
• 220 points

edited May 18, 2020 by Gitika 1,531 views
0 votes
0 answers

TypeError: unsupported operand type(s) for *: 'CommentedMap' and 'CommentedMap' Hatam bu nasıl çözebilirim ?

from ruamel import yaml from scipy import spatial import ...READ MORE

Sep 29, 2020 in Python by anonymous
• 120 points

edited Sep 29, 2020 by Gitika 338 views
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 3,152 views
0 votes
1 answer
0 votes
1 answer

'str' object does not support item assignment

In Python, strings are not very mutable ...READ MORE

answered Feb 22 in Python by Aditya
• 7,660 points
378 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP