471,354 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

string questions

Hi everyone, I'm a beginning programming student in Python and have a
few questions regarding strings.

If s1 = "spam"

If s2 = "ni!"

1. Would string.ljust(string.upper(s2),4) * 3 start it at the left
margin and move it 12 spaces to the right because of the 4 *3? If so,
why is it in the parathesis for the upper command and not the ljust? I
already know that it would cap it to NI!

2. To get the output "Spam Ni! Spam Ni! Spam Ni!" I could do something
like this string.join ([s1, s2]),

But I'm a little lost how to get it repeated three times on one line.
Would I just have to put the same command on the next two lines?

3. To change spam to spm, the string.replace seems to be the best
function to use. However, when I use
string.replace(s1, "a", " ") in python to replace a with an empty space,
it doesn't work...I just get spam back when I print s1. Any ideas?

Thanks.

-Shawn
Sep 15 '07 #1
1 1242
Marc 'BlackJack' Rintsch wrote:
But please don't use the functions in `string` that are also available as
methods on strings. Those functions are deprecated.

Meaning (for newbie clarification):

instead of string.upper(s2), just do s2.upper(). For more detail, see
the docs.

Sep 16 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Robert | last post: by
6 posts views Thread by Nemok | last post: by
7 posts views Thread by millerm | last post: by
14 posts views Thread by Walter Dnes (delete the 'z' to get my real address | last post: by
6 posts views Thread by Gidi | last post: by
5 posts views Thread by Mart | last post: by
4 posts views Thread by Harro de Jong | last post: by
28 posts views Thread by pradeep | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.