Help With Python
Steven Bethard
steven.bethard at gmail.com
Wed Jan 26 11:30:23 EST 2005
Thomas Guettler wrote:
> Am Wed, 26 Jan 2005 15:55:28 +0000 schrieb Judi Keplar:
>
>
>>I am currently taking a course to learn Python and was looking for
>>some help. I need to write a Python statement to print a comma-
>>separated repetition of the word, "Spam", written 511 times ("Spam,
>>Spam, � Spam").
>>
>>Can anybody help me get started? I am completely new to programming!
>
>
> Hi,
>
> # This way, there is a comma after the last:
> import sys
> for i in range(511):
> sys.stdout.write("Spam, ")
>
> # No comma at the end:
> mylist=[]
> for i in range(511):
> mylist.append("Spam")
> print ", ".join(mylist)
# also no comma at the end, using a list comprehension
print ", ".join(["Spam" for _ in xrange(511)])
# also no comma at the end, using a generator expresssion (Python 2.4)
print ", ".join("Spam" for _ in xrange(511))
Steve
More information about the Python-list
mailing list