qa

J

John Machin

I'm trying to get a space in between these two strings but it's ignoring
the space in between when it prints.
string.capwords (string.join([s1 + " " + s2])) * 3 'Spam Ni!Spam Ni!Spam Ni!'

-1. "qa" as a subject heading scarcely invites potential readers to
bother opening up your posting ...
0. Which 2 strings? You have got a space between 'spam' and 'ni'.
1. string.join([ONLY_ONE_element]) is a big fat no-operation.
2. It's ignoring what space when it prints?
3. Break your expression down into simple steps, so that you can see
where you are going wrong, like this:
import string
s1 = 'spam'
s2 = 'ni!'
s3 = s1 + " " + s2
s3 'spam ni!'
list1 = [s3]
list1 ['spam ni!']
s4 = string.join(list1)
s4 'spam ni!'
s5 = string.capwords(s4)
s5 'Spam Ni!'
s6 = s5 * 3
s6 'Spam Ni!Spam Ni!Spam Ni!'

Now: which part(s) of the above are not doing what you expected, and
what did you expect, and what is the basis for your expectation?

4. Almost all of the string module is deprecated -- instead you should
be using methods of string objects. Are you using an old book or
tutorial? If so, throw it away; it's well out of date.

5. capwords breaks the string into words (like the following) which is
a bit silly on a string that you've just laboriously constructed.
.... return " ".join(w.capitalize() for w in s.split())
....
6. What are you actually trying to achieve?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,266
Messages
2,571,075
Members
48,772
Latest member
Backspace Studios

Latest Threads

Top