Reputation: 152
I am extremely new to programming. I have the problem below, where I am trying to list the name of the person with a number next to him. So here, I am trying to join "steve" to "100". I want the outcome to be steve100. The training video says you can't concatenate strings and int's, so you have to type str(grades[1]) to get the 100 to concatenate to steve. However, it doesn't work for me, see below.
>>> grades = ["steve", 100, "john", 50]
>>> grades[0] + grades[1]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot concatenate 'str' and 'int' objects
>>> grades[0] + str(grades[1])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object is not callable
>>>
Upvotes: 1
Views: 10562
Reputation: 1679
You need to parse the int to string, and you are doing it correctly with the str
function:
grades[0]+str(grades[1])
You are getting the error str object is not callable
probably because you have defined a str
variable before.
You can run del str
then try again, it will work =)
Upvotes: 8