Python Forum
Regarding concatenation of a list to a string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regarding concatenation of a list to a string
#1
This is the code I wrote initially,

print("Once upon a time, 5 men were walking by the forest")
warriors = ["Kevin", "Casper", "Nick", "Jim", "Napolean"]
print("The names of these men were: " + (warriors))
However, it gives TypeError : can only concatenate str (not "list") to str

So I modified the code this way:

print("Once upon a time, 5 men were walking by the forest")
warriors = ["Kevin", "Casper", "Nick", "Jim", "Napolean"]
print("The names of these men were: " + str(warriors))
And now its working fine, but I don't understand why

It would be great if you could explain this to me.

Thanks
Reply


Messages In This Thread
Regarding concatenation of a list to a string - by Kedar - Aug-19-2018, 08:02 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries sawtooth500 14 759 Apr-24-2024, 01:42 AM
Last Post: sawtooth500
  FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries i sawtooth500 3 1,697 Mar-22-2024, 03:08 AM
Last Post: deanhystad
  String concatenation in SQL update statement hammer 3 1,583 Feb-24-2022, 08:00 PM
Last Post: hammer
  f string concatenation problem growSeb 3 2,308 Jun-28-2021, 05:00 AM
Last Post: buran
  Concatenation ?? ridgerunnersjw 1 1,749 Sep-26-2020, 07:29 PM
Last Post: deanhystad
  I converted string to 'list', but it doesn't look like a list! mrapple2020 3 3,290 Apr-07-2019, 02:34 PM
Last Post: mrapple2020
  Combining two strings together (not concatenation) DreamingInsanity 6 3,190 Mar-29-2019, 04:32 PM
Last Post: DreamingInsanity
  Create Alert if string from list appears on other list javalava 1 2,548 Sep-17-2018, 02:44 PM
Last Post: DeaD_EyE
  List of pathlib.Paths Not Ordered As Same List of Same String Filenames QbLearningPython 20 15,649 Nov-16-2017, 04:47 PM
Last Post: QbLearningPython
  Create a new list by comparing values in a list and string DBS 2 3,576 Jan-14-2017, 07:59 AM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020