I’m relatively new to python and I’m trying to concatenate with lists. This is my best attempt but obviously it doesn’t work. Anyone know a way to do this? Thanks
present = ["Jake", "Jimmy", "Karen"]
print("The people present are " + present)
>Solution :
you need to convert the list into a string before you can do the string concatenation with the + operator. You can use the str.join() method to accomplish this.
present = ["Jake", "Jimmy", "Karen"]
print("The people present are " + ", ".join(present))
This is going to create a string with each item in the list and use the string ', ' as a separator between each element.
Check out the w3 schools examples here https://www.w3schools.com/python/ref_string_join.asp
Or the official python docs https://docs.python.org/3/library/stdtypes.html#str.join