Help With Python

Kartic kartic.krishnamurthy at gmail.com
Wed Jan 26 11:26:29 EST 2005


Py>>> print "Spam, " * 115
Spam, Spam, Spam, Spam, Spam, ................. Spam,

Multiplies (repeats) the string 115 times.

To eliminate the last ", " (that is, a comma followed by space), you
can do it using the slice notation and say:
Py>>> print ("Spam, " * 115) [:-2]
Spam, Spam, Spam, Spam, Spam, ................., Spam

The [:-2] means that you asking Python to print everything from the
beginning to the last but two characters of the string. You can also
write this as [0:-2]

[or [0:length_of_spam - 2] where length_of_spam = len("Spam, " * 115)]

Since you are starting off, please read and follow the tuturial that
available with your Python installation or on the Python.org site at
http://docs.python.org/tut/tut.html

Thank you,
--Kartic




More information about the Python-list mailing list