Rafael Knuth wrote:
> I want to print individual items from a list like this:
>
> You have a book, towel, shirt, pants in your luggage.
>
> This is my code:
>
> suitcase = ["book", "towel", "shirt", "pants"]
> print ("You have a %s in your luggage." % suitcase)
>
> Instead of printing out the items on the list, my code appends the
> list to the string. How do I need to modify my code?
Have a look at the str.join() method:
>>> suitcase = ["book", "towel", "shirt", "pants"]
>>> print("You have a %s in your luggage." % ", ".join(suitcase))
You have a book, towel, shirt, pants in your luggage.
See <https://docs.python.org/3.6/library/stdtypes.html#str.join>
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor