Print function and spaces
Diez B. Roggisch
nospam-deets at web.de
Thu Feb 5 08:17:05 EST 2004
> def PrintWithoutSpaces(*args):
> output = ""
> for i in args:
> output = output + i
>
> print output
>
>
> if __name__ == "__main__":
> PrintWithoutSpaces("yo", "hello", "gutentag")
> ---snip----
>
> this prints "yohellogutentag"
You function won't work on mixed-type args:
PrintWithoutSpaces("a", 10)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 4, in PrintWithoutSpaces
TypeError: cannot concatenate 'str' and 'int' objects
A better way would be this:
def myprint(*args):
print "".join([str(x) for x in args])
More information about the Python-list
mailing list