Hello Rafael, I believe you are a beginner... That is another way to do this...----------------------------------------------------------------------------------------------------- suitcase = ["book, ", "towel, ", "shirt, ", "pants"] st = ''
for i in suitcase: st = st + i print ("You have a %s in your luggage.") %st ------------------------------------------------------------------------------------------------------------ Best regards... Antonio Zagheni. From: "tutor-requ...@python.org" <tutor-requ...@python.org> To: tutor@python.org Sent: Friday, March 3, 2017 2:00 PM Subject: Tutor Digest, Vol 157, Issue 8 Send Tutor mailing list submissions to tutor@python.org To subscribe or unsubscribe via the World Wide Web, visit https://mail.python.org/mailman/listinfo/tutor or, via email, send a message with subject or body 'help' to tutor-requ...@python.org You can reach the person managing the list at tutor-ow...@python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Tutor digest..." Today's Topics: 1. printing items form list (Rafael Knuth) 2. Re: printing items form list (Peter Otten) ---------------------------------------------------------------------- Message: 1 Date: Fri, 3 Mar 2017 13:12:23 +0100 From: Rafael Knuth <rafael.kn...@gmail.com> To: "Tutor@python.org" <Tutor@python.org> Subject: [Tutor] printing items form list Message-ID: <cam-e2x6f17pop34iewgu-0cj+ccxk3b-vcdwz1atktpu1u9...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 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? == RESTART: C:/Users/Rafael/Documents/01 - BIZ/Python/Python Code/PPC_7.py == You have a ['book', 'towel', 'shirt', 'pants'] in your luggage. ------------------------------ Message: 2 Date: Fri, 03 Mar 2017 13:30:23 +0100 From: Peter Otten <__pete...@web.de> To: tutor@python.org Subject: Re: [Tutor] printing items form list Message-ID: <o9bnkp$cam$1...@blaine.gmane.org> Content-Type: text/plain; charset="ISO-8859-1" 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> ------------------------------ Subject: Digest Footer _______________________________________________ Tutor maillist - Tutor@python.org https://mail.python.org/mailman/listinfo/tutor ------------------------------ End of Tutor Digest, Vol 157, Issue 8 ************************************* _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor