close

How to fix TypeError: can only concatenate str (not “list”) to str

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to fix TypeError: can only concatenate str (not “list”) to str in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to fix TypeError: can only concatenate str (not “list”) to str?

  1. How to fix TypeError: can only concatenate str (not “list”) to str?

    If you use plus sign + in print ('this is old friend' + new_dinner) statement you will get error.

  2. fix TypeError: can only concatenate str (not “list”) to str

    If you use plus sign + in print ('this is old friend' + new_dinner) statement you will get error.

Method 1

Your first line actually produces a tuple of lists, hence cars[0] is a list.

If you print cars you’ll see that it looks like this:

(['rav4'], ['td5'], ['yaris'], ['land rover tdi'])

Get rid of all the square brackets in between and you’ll have a single list that you can index into.

Method 2

new_dinner = ['ali','zeshan','raza']
print ('this is old friend', new_dinner)

use comma , instead of plus +

If you use plus sign + in print ('this is old friend' + new_dinner) statement you will get error.

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read