What is print? A function?

Roy Smith roy at panix.com
Sun Jan 23 16:04:41 EST 2005

Frans Englich <frans.englich at telia.com> wrote:

> Nah, I don't think it's a function, but rather a builtin "statement". But 
> it's possible to invoke it as an function; print( "test" ) works fine.

That's not calling it as a function. The parens in this case are simply 
evaluated as grouping operators around the string literal.
> So I wonder, what _is_ exactly the print statement? The untraditional way of 
> invoking it(without paranteses) makes me wonder.

It's a statement, just like "write" in Fortran.  When C came around, the 
idea of a language having no built-in print statement and having to call 
a function to generate output was "untraditional".  The function was 
named "printf" (with an "f" at the end) to emphasize that it was a 
function call, not a built-in language keyword.  Java, and many other 
quasi-C-based languages also use print functions, and this has become so 
common that people have come to expect it.  It's even a function in 
Perl, although that language's devil-may-care attitude about punctuation 
makes it difficult to tell for sure :-)
> The reason I thinks about this is I need to implement a debug print for my 
> program; very simple, a function/print statement that conditionally prints 
> its message whether a bool is true. Not overly complex.

You can certainly define a function which conditionally calls print, you 
just can't call it "print", because that's a reserved word.  But, before 
you get too far down that path, you might want to explore the logging 
module.  It suffers from a bit of kitchen-sink syndrome, so it may be 
more complicated than you want to deal with, but it's worth taking a 
look at.  You may discover that what you want to do is already done for 

More information about the Python-list mailing list