0

My apologies if this has been answered - I suspect it's very simple - but I can't see how to do it.

It's easier to demonstrate what I want to do.

vflag=True

def printv(*prargs):
    if vflag:
        print prargs
#       print *prargs gives a syntax error, unsurprisingly


printv("hello", "there", "world")
printv("hello", "again")

I want the output to be

hello there world
hello again

and I get (of course)

('hello', 'there', 'world')
('hello', 'again')

1 Answer 1

1

You should do it as:

def printv(*prargs):
    if vflag:
        print ' '.join(prargs)

>>> printv("hello", "there", "world")
hello there world

The string.join(iterable) returns a string of all the elements in the list separated by the specified string, in this case ' ' (a whitespace).

Sign up to request clarification or add additional context in comments.

1 Comment

Well, that was simple - and quick. Thanks very much indeed.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.