Another n00b: Removing the space in "print 'text', var"

Fredrik Lundh fredrik at pythonware.com
Sun Feb 12 17:22:33 EST 2006


"HappyHippy" wrote:

> More of a minor niggle than anything but how would I remove the
> aforementioned space?
>
> eg.
> strName = 'World'
> print 'Hello', strName, ', how are you today?'
>
> comes out as "Hello World , how are you today?"
>
> Have googled, and worked my way through the first 7 chapters of Byte of
> Python, but to no avail...

you can concatenate the strings before passing them to print:

    text = 'Hello' + strName + ', how are you today?'
    print text

or do the same on one line

    print 'Hello' + strName + ', how are you today?'

or use string formatting (the % operator), or write to the special sys.stdout
file object (output to files is discussed in chapter 12).

</F>






More information about the Python-list mailing list