S
Shawn Minisall
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
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