print function question

Bertrand-Xavier M. katsanqat at orange.fr
Tue Jul 25 01:28:00 EDT 2006


On Tuesday 25 July 2006 05:52, Eric Bishop wrote:
> Why does this work:
>
> # start
> a = 5
>
> print a, 'is the number'
>
> #end, prints out "5 is the number"
>
> But not this:
>
> # start
>
> a = 5
>
> print a 'is the number'
>
> #end, errors out
>
> The difference here is the comma seperating the variable and the string
> literal. Is the comma some sort of concatenation operator or is the comma
> necessary in some form of a requirement in the print function, i.e is the
> variable a an argument to print as well as 'is th number' another argument
> to print?

Yes.
It allows to concat several variables, and also adds a space.
These do work as well:

a = 5
print "value is", a
print "value %s" %(a)
print "value is", a, '...'

Regards,
Rob



More information about the Python-list mailing list