• Register
2 votes
401 views

Problem:

Hello all,

I’ve installed python3 and started learning python programming. I am looking for basic problems in different websites and solving them too. I have written a program that should print values inside of a list but it throws an error can't convert 'list' object to str implicitly. Here is my sample code

chars = ['a', 'b', 'c', 'd', 'e']
chars[:3]
print((chars)[:3])
chars[3:]
print((chars)[3:])
print("The value inside the list is :" + chars)

and the output I’m getting

Traceback (most recent call last):
  File "main.py", line 6, in <module>
    print("The value inside the list is :" + chars)
TypeError: cannot concatenate 'str' and 'list' objects

Please pull me up from this mess. I must appreciate your concern and kind help.

Thanks guys.

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

2 votes

Solution:

You need to read the error message thrown back from the compiler very carefully. The error message clearly says that it cannot concatenate 'str' and 'list' objects. So, what is it? This TypeError means you are trying to concatenate a string with a list in your program. A python compiler won’t give you the permission to do so. What can you do? Just cast your list object to a string.

chars = ['a', 'b', 'c', 'd', 'e']
print((chars)[:5])
print("The value inside the list is :" + str(chars))

Boom! Now you are set to go.

13 9 6
94,260 points

Related questions

0 votes
1 answer 5 views
5 views
Problem: can't convert int object to str implicitly. can't convert int object to str implicitly
asked Mar 22 Ifra 25.7k points
1 vote
1 answer 7 views
7 views
Problem: Help is required from some body to convertthis. Typeerror: can't convert 'float' object to str implicitly.
asked Mar 28 PkGuy 14k points
0 votes
1 answer 16 views
16 views
Problem: I am novice to Python and following a tutorial. There is an example of list in the tutorial : example = list('easyhoss') Now, In tutorial, example= ['e','a',...,'s']. But in my case I am getting following error: >>> example = list('easyhoss') ... , line 1, in <module> TypeError: 'list' object is not callable Please tell me where I am wrong. I searched SO this but it is different.
asked Feb 18 Mashhoodch 13k points
0 votes
1 answer 22 views
22 views
Problem: I am working on exercise 41 in learnpythonthehardway and keep getting the error: Traceback (most recent call last): File ".\url.py", line 72, in <module> question, answer = convert(snippet, phrase) File ".\url.py", line 50, in convert result = result ... TypeError: Can't convert 'bytes' object to str implicitly I am using python3 while the books uses python2, so I have made some changes.
asked Feb 23 Mashhoodch 13k points
0 votes
1 answer 43 views
43 views
Problem: Hello! I am a beginner. I just moved from Java to Python programming just recently. I am learning the syntax of Python. I am trying to print the multiplication table using the while loop. I have written the following program in an attempt to do that: number ... to str implicitly I do not have any clue regarding this error. Can anybody here help me solving this error? I would be thankful.
asked Jan 8 Code Learner 9.5k points
0 votes
1 answer 35 views
35 views
Problem: How to I Solve this : python typeerror: 'str' object is not callable HELP! I need help understanding this: python typeerror: 'str' object is not callable Can someone please help solve this, I am new in python().
asked Mar 2 Mashhoodch 13k points
0 votes
1 answer 38 views
38 views
Problem: Hello all, I was solving some mathematical problems using the python programming language. Recently, I solved calculating the factorial value of a number. Now, I want to make a program that can check if a number is prime or not! Therefore, I&rsquo;ve written ... reason? As per my understanding, I haven&rsquo;t used any string in my program. Please, shed some light on this. Thanks.
asked Jul 10, 2020 adamSw 11.3k points
1 vote
1 answer 20 views
20 views
Problem: Hello guys, I am a Java developer and I&rsquo;ve just started learning and practicing python programming. I found the language very smooth and easy to pick up. Let me come to the point straight, I want to break a String in pieces and add every character into a list. More ... 'y', 't', 'h', &lsquo;o&rsquo;, &lsquo;n&rsquo;] at the end of the program. I wonder if I can do this!
asked Jun 2, 2020 adamSw 11.3k points
0 votes
1 answer 17 views
17 views
Problem: The Python &ldquo;typeerror: 'list' object is not callable&rdquo; error is raised when I try to access a list as if it were a function. To solve this error, make sure square brackets are used to access or change values in a list rather than curly brackets.
asked Jan 24 Mashhoodch 13k points
0 votes
1 answer 2 views
2 views
Problem: Any suggestions? typeerror: can't implicitly convert 'bytes' object to str?
asked 4 days ago jamuna1 23.1k points