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
#2
you cannot add objects of different type - str and list.
by the way, it's better to use advanced string formatting methods, rather than convert the list to str and then using +
warriors = ["Kevin", "Casper", "Nick", "Jim", "Napolean"]
print("The names of these men were: {}".format(', '.join(warriors)))
in python 3.6+ you can also use the f-string syntax.
Advanced formatting will be much more handy when it comes to using different types, e.g. numbers
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: Regarding concatenation of a list to a string - by buran - Aug-19-2018, 11:14 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries sawtooth500 14 1,309 Apr-24-2024, 01:42 AM
Last Post: sawtooth500
  FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries i sawtooth500 3 2,442 Mar-22-2024, 03:08 AM
Last Post: deanhystad
  String concatenation in SQL update statement hammer 3 1,643 Feb-24-2022, 08:00 PM
Last Post: hammer
  f string concatenation problem growSeb 3 2,359 Jun-28-2021, 05:00 AM
Last Post: buran
  Concatenation ?? ridgerunnersjw 1 1,793 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,354 Apr-07-2019, 02:34 PM
Last Post: mrapple2020
  Combining two strings together (not concatenation) DreamingInsanity 6 3,263 Mar-29-2019, 04:32 PM
Last Post: DreamingInsanity
  Create Alert if string from list appears on other list javalava 1 2,578 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,860 Nov-16-2017, 04:47 PM
Last Post: QbLearningPython
  Create a new list by comparing values in a list and string DBS 2 3,624 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